Format: application/x-python-code
⬇ Download File (23.9 KB)
   1  o
   2  
   3  �h�W�@s6ddlmZddlmZddlmZddlmZddlmZddl	m
   4  Z
   5  ddlmZm
   6  Z
   7  ddlmZmZdd	lmZmZmZmZdd
   8  lmZmZmZmZmZddlmZmZddlm Z dd
   9  l!m"Z"m#Z#ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0m1Z1Gdd�de�Z2Gdd�de�Z3Gdd�de(�Z4Gdd�de)�Z5Gdd�de�Z6Gdd�de6�Z7Gdd�de6�Z8Gd d!�d!e8�Z9Gd"d#�d#e8�Z:Gd$d%�d%e�Z;Gd&d'�d'e�Z<Gd(d)�d)e&e�Z=Gd*d+�d+e�Z>Gd,d-�d-e�Z?Gd.d/�d/e�Z@Gd0d1�d1e�ZAGd2d3�d3e,�ZBGd4d5�d5e#�ZCd6S)7�)�abstractproperty)�search_ancestor)�debug)�settings)�compiled)�CompiledValueFilter)�values_from_qualified_names�is_big_annoying_library)�AbstractFilter� AnonymousFunctionExecutionFilter)�	ValueName�TreeNameDefinition�	ParamName�NameWrapper)�Value�	NO_VALUES�ValueSet�iterator_to_value_set�ValueWrapper)�LazyKnownValue�LazyKnownValues)�inference_state_method_cache)�ValuesArguments�TreeArgumentsWrapper)�
  10  FunctionValue�
  11  FunctionMixin�OverloadedFunctionValue�BaseFunctionExecutionContext�FunctionExecutionContext�FunctionNameInClass)�ClassFilter)�get_dynamic_array_instance)�function_is_staticmethod�function_is_classmethodcs,eZdZ�fdd�Zdd�Zdd�Z�ZS)�InstanceExecutedParamNamecst�j||dd�||_dS)N��	arguments��super�__init__�	_instance)�self�instanceZfunction_value�	tree_name��	__class__��Sc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/value/instance.pyr)s�
  12  z"InstanceExecutedParamName.__init__cCst|jg�S�N)rr*�r+r0r0r1�infer �zInstanceExecutedParamName.infercC�dS�NTr0r3r0r0r1�matches_signature#�z+InstanceExecutedParamName.matches_signature)�__name__�
  13  __module__�__qualname__r)r4r8�
  14  __classcell__r0r0r.r1r$sr$cs(eZdZ�fdd�Z�fdd�Z�ZS)�AnonymousMethodExecutionFilterc�t�j|i|��||_dSr2r'�r+r,�args�kwargsr.r0r1r)(�
  15  z'AnonymousMethodExecutionFilter.__init__csT|jdkr#t|jj�rt|j��|j|�St|jj�s#t|j|j|�St��	||�S�Nr)
  16  �position_indexr#Z_function_value�	tree_noder$r*�py__class__r"r(�_convert_param)r+�param�namer.r0r1rH,s
  17  ��z-AnonymousMethodExecutionFilter._convert_param)r:r;r<r)rHr=r0r0r.r1r>'sr>cs.eZdZ�fdd�Zddd�Zdd�Z�ZS)	�AnonymousMethodExecutionContextc�t��|�||_dSr2�r(r)r,)r+r,�valuer.r0r1r)>�
  18  z(AnonymousMethodExecutionContext.__init__Nccs�t|j||j||d�VdS)N)�until_position�origin_scope)r>r,�_value)r+rPrQr0r0r1�get_filtersBs�
  19  �z+AnonymousMethodExecutionContext.get_filterscCs,t|j���}t|j|j|dj�|d<|SrD)�listrR�get_param_namesr$r,r-)r+Zparam_namesr0r0r1rUIs�z/AnonymousMethodExecutionContext.get_param_names)NN)r:r;r<r)rSrUr=r0r0r.r1rK=s
  20  rKcseZdZ�fdd�Z�ZS)�MethodExecutionContextcr?r2rMr@r.r0r1r)UrCzMethodExecutionContext.__init__)r:r;r<r)r=r0r0r.r1rVTsrVcs�eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
  21  d�Zdd
  22  �Z	e
  23  dd��Zdd�Zdd�Z
  24  dd�Zd dd�Z�fdd�Zd!�fdd�	Zdd�Z�ZS)"�AbstractInstanceValuer,cst��||�||_dSr2)r(r)�class_value)r+�inference_state�parent_contextrXr.r0r1r)]s
  25  zAbstractInstanceValue.__init__cCr6r7r0r3r0r0r1�is_instancecr9z!AbstractInstanceValue.is_instancecCs
  26  |j��Sr2)rX�get_qualified_namesr3r0r0r1r\fs
  27  z)AbstractInstanceValue.get_qualified_namescC�|jSr2�rXr3r0r0r1�get_annotated_class_objecti�z0AbstractInstanceValue.get_annotated_class_objectcCr]r2r^r3r0r0r1rGlr`z!AbstractInstanceValue.py__class__cCsdSr2r0r3r0r0r1�
  28  py__bool__o�z AbstractInstanceValue.py__bool__cCst�r2)�NotImplementedErrorr3r0r0r1rJsrbzAbstractInstanceValue.namecs*��d����j�}�fdd�|��D�S)N�__call__c�g|]}|����qSr0��bind)�.0�sr3r0r1�
  29  <listcomp>y�z8AbstractInstanceValue.get_signatures.<locals>.<listcomp>)�py__getattribute__�	py__get__rX�get_signatures)r+Z
  30  call_funcsr0r3r1rnwsz$AbstractInstanceValue.get_signaturescCs,|jdd�D]
  31  }|�|�}|r|SqgS)NF)�include_self_names)rS�get)r+rJ�filter�namesr0r0r1�get_function_slot_names{s
  32  �z-AbstractInstanceValue.get_function_slot_namescst��fdd�|D��S)Nc3s�|]
  33  }|��j��VqdSr2)r4Zexecute_with_values�rhrJ��
  34  inferred_argsr0r1�	<genexpr>�s
  35  ��
  36  �z?AbstractInstanceValue.execute_function_slots.<locals>.<genexpr>)r�	from_sets)r+rrrvr0rur1�execute_function_slots�s�z,AbstractInstanceValue.execute_function_slotsTcCs|��Sr2)�
  37  py__name__)r+Zadd_class_infor0r0r1�
  38  get_type_hint�sz#AbstractInstanceValue.get_type_hintcs>|�d�}|st��||�St|g��t��fdd�|D��S)N�__getitem__c3��|]
  39  }|�����VqdSr2�r4�executert�rAr0r1rw���z6AbstractInstanceValue.py__getitem__.<locals>.<genexpr>)rsr(�
  40  py__getitem__rrrx)r+Zindex_value_set�contextualized_noderrr.r�r1r��s
  41  �
  42  z#AbstractInstanceValue.py__getitem__Ncs0��d���s
  43  t����S���fdd�}|�S)N�__iter__c3s&�����D]
  44  }|���EdHqdSr2)ry�
  45  py__next__)�	generator�r�Ziter_slot_namesr+r0r1�iterate�s��z1AbstractInstanceValue.py__iter__.<locals>.iterate)rsr(�
  46  py__iter__)r+r�r�r.r�r1r��s
  47  
  48  z AbstractInstanceValue.py__iter__cC�d|jj|jfS)Nz
  49  <%s of %s>)r/r:rXr3r0r0r1�__repr__��zAbstractInstanceValue.__repr__)Tr2)r:r;r<�api_typer)r[r\r_rGrarrJrnrsryr{r�r�r�r=r0r0r.r1rWZs"
  50  
  51  
  52  
  53  rWcs:eZdZ�fdd�Zddd�Zedd��Zd	d
  54  �Z�ZS)�CompiledInstancecst��|||�||_dSr2)r(r)�
  55  _arguments�r+rYrZrXr&r.r0r1r)�s
  56  zCompiledInstance.__init__NTccs2�|��}|j|dd�}|D]}t||�VqdS�NT)rQr[)r_rS�CompiledInstanceClassFilter)r+rQrorX�
  57  class_filters�fr0r0r1rS�s���zCompiledInstance.get_filterscCst�||jjj�Sr2)rZCompiledValueNamerXrJ�string_namer3r0r0r1rJ��zCompiledInstance.namecCr6)NFr0r3r0r0r1�is_stub�r9zCompiledInstance.is_stubr7)	r:r;r<r)rS�propertyrJr�r=r0r0r.r1r��s
  58  	
  59  r�csfeZdZedd��Zedd��Zddd�Ze�d	d
  60  ��Zdd�Z	dd
  61  d�Z
  62  �fdd�Zdd�Z�Z
  63  S)�_BaseTreeInstancecCs(|j��}|dvr|j����r|SdS)N)rT�set�dict)rXrzrZ�get_root_context�is_builtins_module�r+rJr0r0r1�
  64  array_type�s
  65  �z_BaseTreeInstance.array_typecCst||jjj�Sr2)rrXrJr-r3r0r0r1rJ�sz_BaseTreeInstance.nameNTccs��|��}|r|��D]}|��st|||��|�Vq|j|dd�}|D]}t|t�r3t||�Vq%t|t	�r?t
  66  ||�Vq%|Vq%dSr�)r_�	py__mro__Zis_compiled�SelfAttributeFilter�
  67  as_contextrS�
  68  isinstancer �InstanceClassFilterrr�)r+rQrorX�clsr�r�r0r0r1rS�s$���
  69  
  70  �z_BaseTreeInstance.get_filterscCsh|}	|}t|dd�}|j|ur.t�||�}t|||�}|jjdkr)|�|j�}n|��}nq|�	|�S)NT�funcdefZclassdefr))
  71  rrFrZfrom_context�BoundMethodrJrNr�r��create_context)r+�
  72  class_context�node�newZ	func_node�func�bound_method�contextr0r0r1�create_instance_context�s
  73  �
  74  z)_BaseTreeInstance.create_instance_contextcCsH|��rtSt�|j|�}t|j�rtS|�d�p|�d�}|�||�S)z�
  75          Since nothing was inferred, now check the __getattr__ and
  76          __getattribute__ methods. Stubs don't need to be checked, because
  77          they don't contain any logic.
  78          �__getattr__�__getattribute__)	r�rr�create_simple_objectrYr	rZrsry)r+r�rJrrr0r0r1�py__getattribute__alternatives�s
  79  	
  80  �z0_BaseTreeInstance.py__getattribute__alternativesccs8�d}|�|�}|rt|�|��VdSt�d|�dS)N�__next__z(Instance has no __next__ function in %s.)rsrryr�warning)r+r�rJZnext_slot_namesr0r0r1r�s�
  81  
  82  �z_BaseTreeInstance.py__next__cs2|�d�}|s
  83  t����St��fdd�|D��S)Nrdc3r}r2r~rtr%r0r1rwr�z/_BaseTreeInstance.py__call__.<locals>.<genexpr>)rsr(�
  84  py__call__rrx)r+r&rrr.r%r1r�s
  85  z_BaseTreeInstance.py__call__cCsj|j��D]}|�|||�}|tur|Sq|�d�}|r0|dur)t�|jd�}|�|||�St	|g�S)z"
  86          obj may be None.
  87          �__get__N�None)
  88  rXr�Zpy__get__on_class�NotImplementedrsrZbuiltin_from_namerYryr)r+r,rXr��resultrrr0r0r1rms�
  89  
  90  z_BaseTreeInstance.py__get__r7r2)r:r;r<r�r�rJrSrr�r�r�r�rmr=r0r0r.r1r��s
  91  
  92  
  93  
  94  
  95  
  96  r�csReZdZ�fdd�Zedd�dd��Zdd�Zd	d
  97  �Z�fdd�Zd
  98  d�Z	�Z
  99  S)�TreeInstancecsJ|��dvr|����rtjrt||�}t��|||�||_|j	|_	dS)N)rTr�)
 100  rzr�r�rZdynamic_array_additionsr!r(r)r�rFr�r.r0r1r)2s
 101  �
 102  zTreeInstance.__init__N)�defaultc
 103  Cs�ddlm}m}t||j�}|j�d���D]C}|jj	}|dus*|j
 104  dks*|�|�s+qt||j�
 105  �|j�}||�}||||�}|rY|j�||j||��\}	tjd|	dd�|	SqdS)Nr)�py__annotations__�infer_type_vars_for_executionr)r�zInferred instance value as %sZBLUE)�color)�!jedi.inference.gradual.annotationr�r��InstanceArgumentsr�rXrlrnrNrF�typer8r�r�Zdefine_genericsrZdbg)
 106  r+r�r�rA�	signaturer�r�Zall_annotationsZ
 107  type_var_dictZdefinedr0r0r1�_get_annotated_class_objectAs&���z(TreeInstance._get_annotated_class_objectcCs|��p|jSr2)r�rXr3r0r0r1r_[�z'TreeInstance.get_annotated_class_objectcCsvt}|jdkr9t|j���D]*\}\}}|dur*|dkr*|t�dd�|��D��O}|r8|tt�	|j
 108  |�g�O}q|S)Nr�rcss"�|]}|jdkr|��VqdS�r�N)r��get_key_values)rh�vr0r0r1rwcs�
 109  ��z.TreeInstance.get_key_values.<locals>.<genexpr>)rr��	enumerater��unpackrrxr4rr�rY)r+�values�i�keyr,r0r0r1r�^s
 110  
 111  �
 112  ��zTreeInstance.get_key_valuescsx|jdkr6tt|j����D]'\}}|dur+t��fdd�|��D��}|r*|Sq|�kr5|��Sqt��	��S)Nr�c3s$�|]
 113  }|jdkr|���VqdSr�)r��py__simple_getitem__)rhZ	dct_value��indexr0r1rw{s�
 114  ��z4TreeInstance.py__simple_getitem__.<locals>.<genexpr>)
 115  r��reversedrTr�r�rrxr4r(r�)r+r�r�Zlazy_contextr�r.r�r1r�ps
 116  ���z!TreeInstance.py__simple_getitem__cCsd|jj|j|jfS)Nz<%s of %s(%s)>)r/r:rXr�r3r0r0r1r��s�zTreeInstance.__repr__)r:r;r<r)rr�r_r�r�r�r=r0r0r.r1r�1s
 117  r�c@seZdZdZdS)�AnonymousInstanceN)r:r;r<r�r0r0r0r1r��sr�c@seZdZedd��ZdS)�CompiledInstanceNameccs2�|j��D]}|jdkrt|�Vq|VqdS)N�function)�
 118  _wrapped_namer4r��CompiledBoundMethod�r+Zresult_valuer0r0r1r4�s�
 119  �zCompiledInstanceName.inferN)r:r;r<rr4r0r0r0r1r��sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
 120  r�cC�||_||_dSr2�r*�
 121  _class_filter)r+r,r�r0r0r1r)��
 122  z$CompiledInstanceClassFilter.__init__cC�|�|j�|��Sr2��_convertr�rpr�r0r0r1rp�r�zCompiledInstanceClassFilter.getcC�|�|j���Sr2�r�r�r�r3r0r0r1r���z"CompiledInstanceClassFilter.valuescCsdd�|D�S)NcSsg|]}t|��qSr0)r��rh�nr0r0r1rj�sz8CompiledInstanceClassFilter._convert.<locals>.<listcomp>r0�r+rrr0r0r1r��r�z$CompiledInstanceClassFilter._convertN)r:r;r<r)rpr�r�r0r0r0r1r��s
 123  r�csreZdZ�fdd�Zdd�Ze�fdd��Zdd�Zd	d
 124  �Zddd
 125  �Z	dd�Z
 126  dd�Z�fdd�Zdd�Z
 127  �ZS)r�cst��|�||_||_dSr2)r(r)r,�_class_context)r+r,r�r�r.r0r1r)�s
 128  zBoundMethod.__init__cCr6r7r0r3r0r0r1�is_bound_method�r9zBoundMethod.is_bound_methodcst|jt�j�Sr2)rr�r(rJr3r.r0r1rJ�s�zBoundMethod.namecCst|jdd�\}|S)N�types�
 129  MethodType)rrY)r+�cr0r0r1rG�szBoundMethod.py__class__cCs|dusJ�t|j|�Sr2)r�r,�r+r&r0r0r1�_get_arguments�szBoundMethod._get_argumentsNcCs,|dur
 130  t|j|�S|�|�}t|j||�Sr2)rKr,r�rVr�r0r0r1�_as_context�s
 131  zBoundMethod._as_contextcCs0t|jt�r|j�|�|��S|�|�}|��Sr2)r��_wrapped_valuerr�r�r�r4)r+r&Zfunction_executionr0r0r1r��s
 132  zBoundMethod.py__call__c��fdd��j��D�S)Nc�g|]
 133  }t�j�j|��qSr0)r�r,r�)rhr�r3r0r1rj�s��z7BoundMethod.get_signature_functions.<locals>.<listcomp>)r��get_signature_functionsr3r0r3r1r��s
 134  �z#BoundMethod.get_signature_functionscs�fdd�t���D�S)Ncrer0rf�rh�sigr3r0r1rj�rkz.BoundMethod.get_signatures.<locals>.<listcomp>)r(rnr3r.r3r1rn��zBoundMethod.get_signaturescCr�)Nz<%s: %s>)r/r:r�r3r0r0r1r��r�zBoundMethod.__repr__r2)r:r;r<r)r�r�rJrGr�r�r�r�rnr�r=r0r0r.r1r��s
 135  r�c@seZdZdd�Zdd�ZdS)r�cCr6r7r0r3r0r0r1r��r9z#CompiledBoundMethod.is_bound_methodcr�)Ncrer0rfr�r3r0r1rj�rkz6CompiledBoundMethod.get_signatures.<locals>.<listcomp>)r�rnr3r0r3r1rn�r�z"CompiledBoundMethod.get_signaturesN)r:r;r<r�rnr0r0r0r1r��sr�cs<eZdZdZdd�Zedd��Zdd�Z�fdd	�Z�Z	S)
 136  �SelfNamez9
 137      This name calculates the parent_context lazily.
 138      cCs||_||_||_dSr2)r*r�r-)r+r,r�r-r0r0r1r)�s
 139  zSelfName.__init__cCs|j�|j|j�Sr2)r*r�r�r-r3r0r0r1rZ�r�zSelfName.parent_contextcCr]r2�r*r3r0r0r1�get_defining_qualified_value�r`z%SelfName.get_defining_qualified_valuecs^t|jd�}|dur*|jdjdkr*ddlm}||j|jdjd���}|r*|St��	�S)NZ	expr_stmt�Z	annassignr)�infer_annotation)
 140  rr-�childrenr�r�r�rZZexecute_annotationr(r4)r+�stmtr�r�r.r0r1r4�s��
 141  zSelfName.infer)
 142  r:r;r<�__doc__r)r�rZr�r4r=r0r0r.r1r��s
 143  r�cs8eZdZ�fdd�Zedd��Zdd�Zdd�Z�ZS)	�LazyInstanceClassNamecrLr2r')r+r,Zclass_member_namer.r0r1r)rOzLazyInstanceClassName.__init__ccs0�|j��D]}|�|j|j���EdHqdSr2)r�r4rmr*rGr�r0r0r1r4s��zLazyInstanceClassName.infercCs|����Sr2)r4rnr3r0r0r1rnr5z$LazyInstanceClassName.get_signaturescCr]r2r�r3r0r0r1r�r`z2LazyInstanceClassName.get_defining_qualified_value)	r:r;r<r)rr4rnr�r=r0r0r.r1r�s
 144  r�c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
 145  d�ZdS)
 146  r�z�
 147      This filter is special in that it uses the class filter and wraps the
 148      resulting names in LazyInstanceClassName. The idea is that the class name
 149      filtering can be very flexible and always be reflected in instances.
 150      cCr�r2r�)r+r,Zclass_filterr0r0r1r)r�zInstanceClassFilter.__init__cCr�r2r�r�r0r0r1rpr�zInstanceClassFilter.getcCr�r2r�r3r0r0r1r�r�zInstanceClassFilter.valuesc��fdd�|D�S)Ncsg|]}t�j|��qSr0)r�r*r�r3r0r1rj#s
 151  ��z0InstanceClassFilter._convert.<locals>.<listcomp>r0r�r0r3r1r�"s
 152  �zInstanceClassFilter._convertcCr�)Nz<%s for %s>)r/r:r�r3r0r0r1r�(r�zInstanceClassFilter.__repr__N)	r:r;r<r�r)rpr�r�r�r0r0r0r1r�sr�csHeZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
 153  d�Zdd
 154  �Z	�Z
 155  S)r�zU
 156      This class basically filters all the use cases where `self.*` was assigned.
 157      cst�j|||dd�||_dS)NT)rX�node_contextrQr[r')r+r,Zinstance_classr�rQr.r0r1r)0s�
 158  zSelfAttributeFilter.__init__cs0|jj|jj����fdd�|D�}|�|�S)Ncs*g|]}�|jkr�krnn|�qSr0)�	start_posr���end�startr0r1rj;s*z/SelfAttributeFilter._filter.<locals>.<listcomp>)�
 159  _parser_scoper��end_pos�_filter_self_namesr�r0rr1�_filter9s
 160  zSelfAttributeFilter._filterccsj�|D]/}|j}|jdkr2t|jj�dkr2|jddkr2|��r2|�|�r2|�|jjd|�r2|VqdS)N�trailer�r�.)�parentr��lenr�Z
 161  is_definitionZ_access_possible�_is_in_right_scope)r+rrrJrr0r0r1r>s�
 162  ��z&SelfAttributeFilter._filter_self_namescs2�j�|�}|j||jd�}t�fdd�|D��S)N)�positionc3s8�|]}|jdko|j��jdko|jj�juVqdS)rIrN)r�r-Zget_definitionrErZrFrr�r3r0r1rwMs�
 163  ��
 164  �z9SelfAttributeFilter._is_in_right_scope.<locals>.<genexpr>)�
 165  _node_contextr�Zgotor��any)r+�	self_namerJZself_contextrrr0r3r1rJs
 166  �z&SelfAttributeFilter._is_in_right_scopecr�)Ncr�r0)r�r*rrtr3r0r1rjUsz6SelfAttributeFilter._convert_names.<locals>.<listcomp>r0r�r0r3r1�_convert_namesTr�z"SelfAttributeFilter._convert_namescCs|Sr2r0r�r0r0r1�_check_flowsWr9z SelfAttributeFilter._check_flows)r:r;r<r�r)rrrrrr=r0r0r.r1r�,s	
 167  r�cs&eZdZ�fdd�Zddd�Z�ZS)r�crLr2rM)r+r,r&r.r0r1r)\rOzInstanceArguments.__init__Nccs(�dt|j�fV|j�|�EdHdSr2)rr,Z_wrapped_argumentsr�)r+r�r0r0r1r�`s�zInstanceArguments.unpackr2)r:r;r<r)r�r=r0r0r.r1r�[sr�N)D�abcrZ
 168  parso.treerZjedirrZjedi.inferencerZjedi.inference.compiled.valuerZjedi.inference.helpersrr	Zjedi.inference.filtersr
 169  rZjedi.inference.namesrr
 170  rrZjedi.inference.base_valuerrrrrZjedi.inference.lazy_valuerrZjedi.inference.cacherZjedi.inference.argumentsrrZjedi.inference.value.functionrrrrrrZjedi.inference.value.klassr Z#jedi.inference.value.dynamic_arraysr!Zjedi.parser_utilsr"r#r$r>rKrVrWr�r�r�r�r�r�r�r�r�r�r�r�r�r0r0r0r1�<module>sF 
 171  Mr[
 172  3/