Format: application/x-python-code
⬇ Download File (22.7 KB)
   1  o
   2  
   3  �h�Z�@s�ddlmZddlmZddlmZmZddlmZddl	m
   4  Z
   5  mZddlm
   6  Z
   7  ddlmZmZddlmZdd	lmZdd
   8  lmZddlmZmZddlmZd
   9  d�ZGdd�d�ZGdd�de�ZGdd�de�ZGdd�d�Z Gdd�de e�Z!Gdd�de�Z"Gdd�d�Z#Gdd�de#�Z$Gdd �d e$e�Z%Gd!d"�d"e%�Z&Gd#d$�d$e&�Z'Gd%d&�d&e&�Z(Gd'd(�d(e#�Z)Gd)d*�d*e�Z*Gd+d,�d,e*�Z+Gd-d.�d.�Z,Gd/d0�d0�Z-Gd1d2�d2e-e"�Z.Gd3d4�d4e e�Z/Gd5d6�d6e-e/�Z0d7S)8�)�abstractmethod)�	Parameter)�Optional�Tuple)�search_ancestor)�find_statement_documentation�clean_scope_docstring)�unite)�ValueSet�	NO_VALUES)�inference_state_method_cache)�
  10  docstrings)�memoize_method)�
  11  deep_ast_copy�infer_call_of_leaf)�plugin_managercCs*d}|D]}|r|d7}||��7}q|S)N�z 
  12  ------------------------------
  13  )�	py__doc__)�names�doc�name�r�Jc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/names.py�_merge_name_docssrc@s�eZdZUdZeeeefed<eed<dZ	dZ
  14  dZ	edd��Z
  15  edd��Zdd
  16  d�Zdd
  17  �Zdd�Zdd�Zdd�Zdd�Zdd�Zedd��Zdd�ZdS)�AbstractNameDefinitionN�	start_pos�string_nameTcC�t��N��NotImplementedError��selfrrr�infer&�zAbstractNameDefinition.infercCs|hSrrr!rrr�goto*szAbstractNameDefinition.gotoFcCs6|��}|dus
  18  |s|S|��j}|durdS||Sr)�_get_qualified_names�get_root_context�string_names)r"�include_module_namesZqualified_names�module_namesrrr�get_qualified_names0s
  19  z*AbstractNameDefinition.get_qualified_namescC�dSrrr!rrrr&:r$z+AbstractNameDefinition._get_qualified_namescC�
  20  |j��Sr)�parent_contextr'r!rrrr'>�
  21  z'AbstractNameDefinition.get_root_contextcC�|jSr)rr!rrr�get_public_nameA�z&AbstractNameDefinition.get_public_namecCs2|jdurd|jj|jfSd|jj|j|jfS)Nz<%s: string_name=%s>z!<%s: string_name=%s start_pos=%s>)r�	__class__�__name__rr!rrr�__repr__Ds
  22  
  23  �zAbstractNameDefinition.__repr__cC�dS)NFrr!rrr�	is_importJ�z AbstractNameDefinition.is_importcCr6)Nrrr!rrrrMr8z AbstractNameDefinition.py__doc__cC�|jjSr)r.�api_typer!rrrr:P�zAbstractNameDefinition.api_typecCr6)z�
  24          Returns either None or the value that is public and qualified. Won't
  25          return a function, because a name in a function is never public.
  26          Nrr!rrr�get_defining_qualified_valueTsz3AbstractNameDefinition.get_defining_qualified_value�F)r4�
  27  __module__�__qualname__rrr�int�__annotations__�strr.�	tree_name�
  28  is_value_namerr#r%r+r&r'r1r5r7r�propertyr:r<rrrrrs*
  29  
  30  
  31  
  32  
  33  
  34  rc@s$eZdZdZdZdd�Zdd�ZdS)�AbstractArbitraryNamez�
  35      When you e.g. want to complete dicts keys, you probably want to complete
  36      string literals, which is not really a name, but for Jedi we use this
  37      concept of Name for completions as well.
  38      FcCs||_||_|j|_dSr)�inference_staterZbuiltins_moduler.)r"rG�stringrrr�__init__dszAbstractArbitraryName.__init__cC�tSr�rr!rrrr#ir8zAbstractArbitraryName.inferN)r4r>r?�__doc__rDrIr#rrrrrF\s
  39  rFcs^eZdZdd�Zd�fdd�	Zdd�Zdd	�Zd
  40  d�Zdd
  41  �Ze	dd��Z
  42  e	dd��Z�ZS)�AbstractTreeNamecC�||_||_dSr)r.rC)r"r.rCrrrrIn�
  43  zAbstractTreeName.__init__Fcsdt|jdd�}|dur,|jdkr|������s,|r*|js*tdd�|�|j�D��SdSt��	|�S)N�import_name�import_from�css�|]}|jVqdSr)�value)�.0�nrrr�	<genexpr>|s�z7AbstractTreeName.get_qualified_names.<locals>.<genexpr>)
  44  rrC�levelr'�	get_value�
  45  is_package�tupleZget_path_for_name�superr+)r"r)Zimport_node�r3rrr+rs�
  46  z$AbstractTreeName.get_qualified_namescCs$|j��}|durdS||jjfSr)r.r+rCrS)r"Zparent_namesrrrr&�s
  47  z%AbstractTreeName._get_qualified_namescCs$|��rtd��|jr|j��SdS)Nz&Shouldn't really happen, please report)r7r r.rXr!rrrr<�s
  48  
  49  z-AbstractTreeName.get_defining_qualified_valuecs||j�|j��jdd�}|dur7|j}|dkr#�jjdv}|r"|gSn*|dvr4ddlm}|���}|S|gSddlm}|���}|durMd	d
  50  �|D�S�j}|j}	|	dkr�|jdd
  51  kr�|jd�kr�|j}
  52  |
  53  jdkrp|
  54  j}
  55  |
  56  jdkr�|
  57  jdkr���	|
  58  jd�}n6|
  59  jj�
  60  |
  61  �}|
  62  jjd|�}
  63  |
  64  ddkr�|
  65  �d���	|
  66  d�}ddlm
  67  }|
  68  dd�D]}
  69  |�||
  70  �}q�g}|D]}|��D]}|��D]
  71  }|j�jkr�|�|�q�q�q�|Sn.|	dk�r
  72  |j�
  73  ��}|dk�r
  74  t|�}g|j|dd�<��	|�}t��fdd�|D��S|	dk�r%|jddk�r%t��dd�}|j��d�St�dd��p-�}|jdk�r6�}�j�|jd�S)NT�Zimport_name_always�	expr_stmt)�power�trailer)rQrPr)�goto_import)�%follow_error_node_imports_if_possiblecS�g|]}|j�qSr�r�rTrSrrr�
  75  <listcomp>��z)AbstractTreeName.goto.<locals>.<listcomp>ZargumentrR�=Zarglist�classdef�	decorator�await)�
  76  infer_trailerZdotted_namec3s�|]
  77  }|j��d�VqdS)�Zname_contextN)r%re��contextrrrrV�s
  78  ��
  79  �z(AbstractTreeName.goto.<locals>.<genexpr>r`�.)Zcut_own_trailerrmZlambdef)�position)r.rC�get_definition�type�parent�jedi.inference.importsrarb�children�
  80  infer_node�index�pop�jedi.inference.syntax_treerlZget_signaturesZget_param_namesrrS�appendrr	rr%rr)r"�
  81  definition�type_Zis_simple_namerar*rb�values�parZ	node_typer`Z	value_set�iZto_inferrlZparam_namesrS�	signature�
  82  param_namerxZ
  83  new_dotted�stmtrrnrr%�s��
  84  
  85  $
  86  
  87  
  88  
  89  
  90  ����
  91  
  92  
  93  ���zAbstractTreeName.gotocCst|jdd�}|duS)NrQrP�rrC)r"�imprrrr7�szAbstractTreeName.is_importcCr9r)rCrSr!rrrr�r;zAbstractTreeName.string_namecCr9r)rCrr!rrrr�r;zAbstractTreeName.start_posr=)
  94  r4r>r?rIr+r&r<r%r7rErr�
  95  __classcell__rrr\rrMmsH
  96  rMcsHeZdZdd�Zdd�Zdd�Z�fdd�Zd	d
  97  �Zedd��Z	�Z
  98  S)
  99  �ValueNameMixincCst|jg�Sr)r
 100  �_valuer!rrrr#��zValueNameMixin.infercCsF|j��}|s!|j��r!ddlm}||gdd�}||vr!t|�S|S)Nr��
 101  convert_namesF�Zprefer_stub_to_compiled)r�r�is_stub�!jedi.inference.gradual.conversionr�r)r"rr�rrrrr�s
 102  zValueNameMixin.py__doc__cCr-r)r�r+r!rrrr&�r/z#ValueNameMixin._get_qualified_namescs|jdur
 103  |j��St���Sr)r.r��
 104  as_contextr[r'r!r\rrr'�s
 105  
 106  
 107  zValueNameMixin.get_root_contextcCs,|j}|dur|��s|��r|j��SdSr)r.Z	is_module�is_classrX)r"rorrrr<�s
 108  z+ValueNameMixin.get_defining_qualified_valuecCr9r)r�r:r!rrrr:�r;zValueNameMixin.api_type)r4r>r?r#rr&r'r<rEr:r�rrr\rr��s	r�cs$eZdZ�fdd�Zdd�Z�ZS)�	ValueNamecst��|j|�||_dSr)r[rIr.r�)r"rSrCr\rrrIs
 109  zValueName.__init__cCst|jjg�Sr)r
 110  r�rr!rrrr%	szValueName.goto)r4r>r?rIr%r�rrr\rr�sr�c@sXeZdZedddddd�Zdd�Zedd	��Zd
 111  d�Zedd
 112  ��Z	e
 113  dd�dd��ZdS)�TreeNameDefinition�module�function�param�class)rPrQZfuncdefr�ricCs ddlm}||jj|j|j�S)Nr)�tree_name_to_values)rzr�r.rGrC)r"r�rrrr#s�zTreeNameDefinition.infercCs*|jjdd�}|dur
 114  dS|j�|jd�S)NTr]�	statement)rCrr�
 115  _API_TYPES�getrs)r"r|rrrr:szTreeNameDefinition.api_typec	Cs�g}d}|jj}|j}|dure|jdvrLt|j�D]+\}}||krDt|d�}|r:tt|j�|d�}t||�}|�d||f�nqt	d��d}n|jdkrTd}n|jd	vr\	|S|}|j}|dus|S)
 116  a�
 117          Returns an array of tuple(int, node) of the indexes that are used in
 118          tuple assignments.
 119  
 120          For example if the name is ``y`` in the following code::
 121  
 122              x, (y, z) = 2, ''
 123  
 124          would result in ``[(1, xyz_node), (0, yz_node)]``.
 125  
 126          When searching for b in the case ``a, *b, c = [...]`` it will return::
 127  
 128              [(slice(1, -1), abc_node)]
 129          FN)ZtestlistZ
 130  testlist_compZtestlist_star_exprZexprlist�rzCouldn't find the assignment.Z	star_exprT)r^Z
 131  sync_comp_for)
 132  rCrtrs�	enumeratervr@�len�slice�insert�LookupError)	r"ZindexesZis_star_expr�node�comparer��childrxZfrom_endrrr�assignment_indexes&s4
 133  �
 134  
 135  ��z%TreeNameDefinition.assignment_indexescCr9r)r.rGr!rrrrGOsz"TreeNameDefinition.inference_stater)�defaultcCs�|j}|dvr*|j����r#ddlm}||gdd�}||vr#t|�St|j�	��S|dkr:|�
 136  �}||vr:t|�S|dkrJ|j��rJt|j�	��SdS)	N)r�r�rErr�Fr�r�r�r)
 137  r:r.r'r�r�r�rrrCrrr%Z
 138  is_definitionr)r"r:r�rrrrrTszTreeNameDefinition.py__doc__N)r4r>r?�dictr�r#rEr:r�rGrrrrrrr�
 139  s �	
 140  )
 141  r�c@s2eZdZddd�Zddd�Zdd�Zd
 142  d	d
 143  �ZdS)�_ParamMixinTcC�(tjtjg}|r|�tj�|��|vSr)r�POSITIONAL_ONLY�POSITIONAL_OR_KEYWORDr{�VAR_POSITIONAL�get_kind)r"Zinclude_star�optionsrrr�maybe_positional_argumentl�z%_ParamMixin.maybe_positional_argumentcCr�r)r�KEYWORD_ONLYr�r{�VAR_KEYWORDr�)r"Z
 144  include_starsr�rrr�maybe_keyword_argumentrr�z"_ParamMixin.maybe_keyword_argumentcC�(|��}|tjkrdS|tjkrdSdS)N�*z**r�r�rr�r��r"�kindrrr�_kind_stringxs
 145  
 146  z_ParamMixin._kind_stringFcCr,rr)r"r)rrrr+�r8z_ParamMixin.get_qualified_namesN)Tr=)r4r>r?r�r�r�r+rrrrr�ks
 147  
 148  
 149  r�c@s<eZdZdZdd�Zdd�Zdd�Zedd	��Zd
 150  d�Z	dS)
 151  �ParamNameInterfacer�cCrrrr!rrrr��r8zParamNameInterface.get_kindcCrrrr!rrr�	to_string�r8zParamNameInterface.to_stringcCr6)as
 152          For dealing with type inference and working around the graph, we
 153          sometimes want to have the param name of the execution. This feels a
 154          bit strange and we might have to refactor at some point.
 155  
 156          For now however it exists to avoid infering params when we don't really
 157          need them (e.g. when we can just instead use annotations.
 158          Nrr!rrr�get_executed_param_name�s	z*ParamNameInterface.get_executed_param_namecCr�)NrRr�rr�r�rrr�
 159  star_count�s
 160  
 161  zParamNameInterface.star_countcCrJrrKr!rrr�
 162  infer_default�r8z ParamNameInterface.infer_defaultN)
 163  r4r>r?r:r�r�r�rEr�r�rrrrr��s
 164  r�c@s,eZdZdZdZdd�Zdd�Zdd�ZdS)�BaseTreeParamNameNcCsX|��|��}|j}|j}|dur|d|jdd�7}|dur*|d|jdd�7}|S)Nz: F)Zinclude_prefixrh)r�r1�annotation_node�default_node�get_code)r"�output�
 165  annotationr�rrrr��szBaseTreeParamName.to_stringcCs |j}|�d�r|dd�}|S)N�__r�)r�
 166  startswith�r"rrrrr1�s
 167  z!BaseTreeParamName.get_public_namecKs|gSrr)r"�kwargsrrrr%�r2zBaseTreeParamName.goto)r4r>r?r�r�r�r1r%rrrrr��s
 168  r�cs^eZdZ�fdd�Zdd�Zedd��Zdd	d
 169  �Zdd�Zed
 170  d��Z	dd�Z
 171  dd�Z�ZS)�_ActualTreeParamNamecst��|��|�||_dSr)r[rIZget_default_param_context�function_value)r"r�rCr\rrrI�s�
 172  z_ActualTreeParamName.__init__cCst|jd�S)Nr�r�r!rrr�_get_param_node�r�z$_ActualTreeParamName._get_param_nodecC�
 173  |��jSr)r�r�r!rrrr���
 174  z$_ActualTreeParamName.annotation_nodeTFcCs0ddlm}||j|��|d�}|r|��}|S)Nr)�infer_param)�ignore_stars)Z!jedi.inference.gradual.annotationr�r�r��execute_annotation)r"r�r�r�r~rrr�infer_annotation�s
 175  �z%_ActualTreeParamName.infer_annotationcCs|j}|dur	tS|j�|�Sr)r�rr.rw)r"r�rrrr��sz"_ActualTreeParamName.infer_defaultcCr�r)r�r�r!rrrr��r�z!_ActualTreeParamName.default_nodecCs�|��}|jdkrtjS|jdkrtjS|jj�d�rtjS|j	}d}|j
 176  D]*}|r4|dkr3tjSq&|dkr=tjS|jdkrP|jrJtjS||krPd}q&tj
 177  S)	NrRr�r�F�/r�r�T)r�r�rr�r�rrSr�r�rtrvr�rsr�)r"Z
 178  tree_paramrtZparam_appeared�prrrr��s.
 179  
 180  
 181  
 182  �
 183  
 184  
 185  �z_ActualTreeParamName.get_kindcCs&|��}|r|St�|j|���}|Sr)r�r
 186  r�r�r�)r"r~Z
 187  doc_paramsrrrr#�s
 188  z_ActualTreeParamName.infer)TF)
 189  r4r>r?rIr�rEr�r�r�r�r�r#r�rrr\rr��s
 190  
 191  	
 192  r�cs@eZdZejdd��fdd��Zejdd��fdd��Z�ZS)�AnonymousParamNameZgoto_anonymous_paramrdcs
 193  t���Sr)r[r%r!r\rrr%r�zAnonymousParamName.gotoZinfer_anonymous_paramcs�t���}|r	|Sddlm}|��}||j|j�}|r|S|jdkr1ddlm	}||jj
 194  g�}n"|jdkrDddlm}||jj
 195  i�}n|jdurKt
 196  S|jj�|j�St|h�S)Nr)�dynamic_param_lookuprR)�	FakeTupler�)�FakeDict)r[r#Zjedi.inference.dynamic_paramsr�r�r��position_indexr�Zjedi.inference.value.iterabler�rGr�r�rr.rwr
 197  )r"r~r�r�r�rSr�r\rrr#	s$
 198  
 199  
 200  
 201  
 202  zAnonymousParamName.infer)r4r>r?rZdecorater%r#r�rrr\rr�s
 203  
 204  
 205  r�cs0eZdZ�fdd�Z�fdd�Zdd�Z�ZS)�	ParamNamecst��||�||_dSr)r[rI�	arguments)r"r�rCr�r\rrrI"s
 206  zParamName.__init__cst���}|r	|S|����Sr)r[r#r�)r"r~r\rrr#&s
 207  zParamName.infercCs(ddlm}||j|j�}||��jS)Nr)�get_executed_param_names)Zjedi.inference.paramr�r�r�r�r�)r"r�Zparams_namesrrrr�-sz!ParamName.get_executed_param_name)r4r>r?rIr#r�r�rrr\rr�!sr�c@�$eZdZdd�Zdd�Zdd�ZdS)�ParamNameWrappercC�
 208  ||_dSr)�_wrapped_param_name)r"r�rrrrI4r/zParamNameWrapper.__init__cC�t|j|�Sr)�getattrr�r�rrr�__getattr__7r�zParamNameWrapper.__getattr__cC�d|jj|jfS)Nz<%s: %s>)r3r4r�r!rrrr5:�zParamNameWrapper.__repr__N�r4r>r?rIr�r5rrrrr�3�r�c@sZeZdZdZdZdd�Zddd�Zedd	��Ze	d
 209  d��Z
 210  dd
 211  �Zedd��Zdd�Z
 212  dS)�
 213  ImportName�rRrrcCrNr)�_from_module_contextr)r"r.rrrrrIBrOzImportName.__init__FcCsH|r"|jr|jdksJd��|jj}|dur|S||jfS|jfSdS)NrRz(Everything else is not supported for nowr)�_levelr�r(r)r"r)r*rrrr+FszImportName.get_qualified_namescCs&|j}|��}|s|Stt|����Sr)r�r#�next�iterr�)r"�mZ
 214  import_valuesrrrr.Qs
 215  zImportName.parent_contextcCs.ddlm}|j}||j|jg||jd���S)Nr)�Importer)rW)rur�r�rGrr��follow)r"r�r�rrrr#[szImportName.infercCsdd�|��D�S)NcSrcrrd)rTr�rrrrfbrgz#ImportName.goto.<locals>.<listcomp>)r#r!rrrr%ar�zImportName.gotocCr6)Nr�rr!rrrr:dr$zImportName.api_typecCst|���Sr)rr%r!rrrrhr�zImportName.py__doc__Nr=)r4r>r?rr�rIr+rEr.rr#r%r:rrrrrr�>s
 216  
 217  	
 218  
 219  r�c@seZdZdZdS)�
 220  SubModuleNamerRN)r4r>r?r�rrrrr�lsr�c@r�)�NameWrappercCr�r)�
 221  _wrapped_name)r"Zwrapped_namerrrrIqr/zNameWrapper.__init__cCr�r)r�r�r�rrrr�tr�zNameWrapper.__getattr__cCr�)Nz%s(%s))r3r4r�r!rrrr5wr�zNameWrapper.__repr__Nr�rrrrr�pr�r�c�eZdZ�fdd�Z�ZS)�
 222  StubNameMixincsdddlm}|g}|jdkrd|j��jvrdd�|��D�}||dd�}||vr.t���St	|�S)	Nrr�r�rhcSrcrrd)rT�vrrrrf�rgz+StubNameMixin.py__doc__.<locals>.<listcomp>Fr�)
 223  r�r�r:rCrrrvr#r[rr)r"r�rr\rrr|s
 224  zStubNameMixin.py__doc__)r4r>r?rr�rrr\rr�{�r�cr�)�StubNamecsJt���}|jdkr#|����dkr#ddlm�t�fdd�|D��S|S)N�version_info�sysr��VersionInfoc3s�|]}�|�VqdSrr)rT�cr�rrrV�s�z!StubName.infer.<locals>.<genexpr>)r[r#rr'Z
 225  py__name__Z!jedi.inference.gradual.stub_valuer�r
 226  )r"�inferredr\r�rr#�s
 227  
 228  zStubName.infer)r4r>r?r#r�rrr\rr��r�r�c@s$eZdZdZdd�Zedd��ZdS)�
 229  ModuleNamer�cCrNr)r��_name)r"rSrrrrrI�rOzModuleName.__init__cCr0r)r�r!rrrr�szModuleName.string_nameN)r4r>r?rrIrErrrrrr��s
 230  r�c@seZdZdS)�StubModuleNameN)r4r>r?rrrrr��sr�N)1�abcr�inspectr�typingrrZ
 231  parso.treerZjedi.parser_utilsrrZjedi.inference.utilsr	Zjedi.inference.base_valuer
 232  rZjedi.inference.cacherZjedi.inferencer
 233  Z
 234  jedi.cacherZjedi.inference.helpersrrZjedi.pluginsrrrrFrMr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�<module>sB@w 	^!E.