Format: application/x-python-code
⬇ Download File (7.2 KB)
   1  o
   2  
   3  �hg�@s�dZddlmZddlmZddlmZddlmZmZm	Z	m
   4  Z
   5  ddlmZddl
   6  mZddlmZe�Zd	d
   7  �Zeed�ejdd
   8  ���Zdd�ZGdd�de	�ZGdd�de
   9  �ZGdd�de�ZGdd�de�ZdS)a�
  10  A module to deal with stuff like `list.append` and `set.add`.
  11  
  12  Array modifications
  13  *******************
  14  
  15  If the content of an array (``set``/``list``) is requested somewhere, the
  16  current module will be checked for appearances of ``arr.append``,
  17  ``arr.insert``, etc.  If the ``arr`` name points to an actual array, the
  18  content will be added
  19  
  20  This can be really cpu intensive, as you can imagine. Because |jedi| has to
  21  follow **every** ``append`` and check whether it's the right array. However this
  22  works pretty good, because in *slow* cases, the recursion detector and other
  23  settings will stop this process.
  24  
  25  It is important to note that:
  26  
  27  1. Array modifications work only in the current module.
  28  2. Jedi only checks Array additions; ``list.pop``, etc are ignored.
  29  �)�debug)�settings)�	recursion)�ValueSet�	NO_VALUES�HelperValueMixin�ValueWrapper)�LazyKnownValues)�infer_call_of_leaf)�inference_state_method_cachecCs|jdvrtSt||�S)zI Just a mapper function for the internal _internal_check_array_additions )�list�set)Z
  30  array_typer�_internal_check_array_additions)�context�sequence�r�Yc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/value/dynamic_arrays.py�check_array_additions"s
  31  
  32  r)�defaultc
  33  s�ddlm�tjd|dd�|��}tjr|��r#tjddd�tS�fdd�}tj	d	}t_	|j
  34  jd
  35  k}|r<gd�ndd
  36  g}t�}|D]�}z	|j
  37  ��|}	Wn	tyYYqEw|	D]{}
  38  |j
  39  }|j|
  40  jkrn|jkspnq\|
  41  j}|j}
  42  |
  43  j�|�}z	|
  44  j|d}Wn	ty�Yq\w|jdks�|jddks�|jddkr�q\|�|
  45  �}t�|j|
  46  �� }|r�t||
  47  dd�}||vr�||||jd|�O}Wd�n1s�wYq\qE|t_	tjd|dd�|S)zr
  48      Checks if a `Array` has "add" (append, insert, extend) statements:
  49  
  50      >>> a = [""]
  51      >>> a.append(1)
  52      r��	argumentszDynamic array search for %sZMAGENTA)�colorzDynamic array search aborted.cs�t��|j||����}t�}|dvr|dd�}|dvr+|D]	\}}|�|�q|S|dvr@|D]\}}|t|�����O}q1|S)N)�insert�)�append�addr)�extend�update)r�
  53  TreeArguments�inference_state�unpackr
  54  r�infer�iterate)rZarglist�add_name�params�result�key�
  55  lazy_valuerrr�find_additions<s�z7_internal_check_array_additions.<locals>.find_additionsFr)rrrrrr�trailer�(�)T)Zcut_own_trailerNzDynamic array result %s)�jedi.inferencerrZdbgZget_root_contextrZdynamic_array_additionsZis_compiledrZ dynamic_params_for_other_modules�nameZstring_namer
  56  Z	tree_nodeZget_used_names�KeyError�	start_pos�end_pos�parent�children�index�
  57  IndexError�typeZcreate_contextrZexecution_allowedrr
  58  )rrZmodule_contextr(Ztemp_param_addZis_listZsearch_namesZadded_typesr#Zpossible_namesr-Z
  59  value_noder)�powerZtrailer_posZexecution_trailerZrandom_context�allowed�foundrrrr+sn	���
  60  
  61  ������#rcCs(t||�}ddlm}|�t|g�g�S)z$Used for set() and list() instances.rr)�_DynamicArrayAdditionsr,rZValuesArgumentsr)�instancerZairrr�get_dynamic_array_instance~s
  62  r;c@s4eZdZdZdd�Zdd�Zddd�Zd
  63  d
  64  d�ZdS)r9aj
  65      Used for the usage of set() and list().
  66      This is definitely a hack, but a good one :-)
  67      It makes it possible to use set/list conversions.
  68  
  69      This is not a proper context, because it doesn't have to be. It's not used
  70      in the wild, it's just used within typeshed as an argument to `__init__`
  71      for set/list and never used in any other place.
  72      cCs||_||_dS�N)�	_instance�
  73  _arguments)�selfr:rrrr�__init__�s
  74  z_DynamicArrayAdditions.__init__cCs|jjj�d�\}|S)N�tuple)r=rZbuiltins_moduleZpy__getattribute__)r?�tuple_rrr�py__class__�sz"_DynamicArrayAdditions.py__class__Nccsx�|j}z
  75  t|���\}}Wn	tyYn
  76  w|����EdHddlm}t||�r:t	|j
  77  |j�}|EdHdSdS)Nr)r)r>�nextr �
  78  StopIterationr!r"Zjedi.inference.argumentsr�
  79  isinstancerrr=)r?�contextualized_noder�_r'r�	additionsrrr�
  80  py__iter__�s��
  81  �z!_DynamicArrayAdditions.py__iter__FcCs
  82  |�|�Sr<)rJ)r?rG�is_asyncrrrr"�s
  83  z_DynamicArrayAdditions.iterater<)NF)�__name__�
  84  __module__�__qualname__�__doc__r@rCrJr"rrrrr9�s	
  85  r9cs,eZdZ�fdd�Zdd�Zdd�Z�ZS)�
  86  _Modificationcst��|�||_||_dSr<)�superr@�_assigned_values�_contextualized_key)r?Z
  87  wrapped_valueZassigned_valuesZcontextualized_key��	__class__rrr@�s
  88  z_Modification.__init__cOs|jj|i|��|jBSr<)�_wrapped_value�
  89  py__getitem__rR)r?�args�kwargsrrrrW�sz_Modification.py__getitem__cCs.dd�|j��D�}||vr|jS|j�|�S)NcSsg|]}|�t��qSr)Zget_safe_value�	_sentinel)�.0�vrrr�
  90  <listcomp>�s��z6_Modification.py__simple_getitem__.<locals>.<listcomp>)rSr!rRrV�py__simple_getitem__)r?r3�actualrrrr^�s�z"_Modification.py__simple_getitem__)rLrMrNr@rWr^�
  91  __classcell__rrrTrrP�srPc@seZdZddd�Zdd�ZdS)�DictModificationNccs �|j�|�EdH|jVdSr<)rVrJrS�r?rGrrrrJ�s�zDictModification.py__iter__cCs|j��|j��BSr<)rV�get_key_valuesrSr!)r?rrrrc�szDictModification.get_key_valuesr<)rLrMrNrJrcrrrrra�s
  92  rac@seZdZddd�ZdS)�ListModificationNccs$�|j�|�EdHt|j�VdSr<)rVrJr	rRrbrrrrJ�s�zListModification.py__iter__r<)rLrMrNrJrrrrrd�srdN)rOZjedirrr,rZjedi.inference.base_valuerrrrZjedi.inference.lazy_valuer	Zjedi.inference.helpersr
  93  Zjedi.inference.cacher�objectrZrZincrease_indentrr;r9rPrardrrrr�<module>s$	Q$