Format: application/x-python-code
⬇ Download File (21.3 KB)
   1  o
   2  
   3  �hS�@s�dZddlZddlmZddlmZddlmZddlm	Z	ddl
   4  mZddlm
   5  Z
   6  dd	lmZdd
   7  lmZddlmZmZmZddlmZmZmZdd
   8  lmZddlmZddlmZddl m!Z!ddl"m#Z#ddl$m%Z%m&Z&Gdd�d�Z'Gdd�de�Z(Gdd�de(�Z)Gdd�de�Z*Gdd�dee�Z+Gdd�dee�Z,Gdd �d ee�Z-Gd!d"�d"e�Z.Gd#d$�d$e�Z/d%d&d'd(d&d)�Z0d*d+�Z1d,d-�Z2d.d/�Z3d0d1�Z4e3e�d2d3���Z5dS)4z$
   9  Imitate the parser representation.
  10  �N)�partial)�	Parameter)�Path)�Optional)�debug)�to_list)�memoize_method)�AbstractFilter)�AbstractNameDefinition�ValueNameMixin�ParamNameInterface)�Value�ValueSet�	NO_VALUES)�LazyKnownValue)�	_sentinel)�inference_state_function_cache)�reraise_getitem_errors)�BuiltinSignature)�CompiledContext�CompiledModuleContextc@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
  11  �CheckAttributezARaises :exc:`AttributeError` if the attribute X is not available.NcCs
  12  ||_dS�N)�
  13  check_name)�selfr�r�Sc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/compiled/value.py�__init__�
  14  zCheckAttribute.__init__cCs$||_|jdur|jdd�|_|S)N�)�funcr�__name__)rr rrr�__call__s
  15  zCheckAttribute.__call__cCs&|dur|S|j�|j�t|j|�Sr)�
  16  access_handle�
  17  getattr_pathsrrr )r�instance�ownerrrr�__get__%szCheckAttribute.__get__r)r!�
  18  __module__�__qualname__�__doc__rr"r'rrrrrs
  19  
  20  rcs~eZdZdL�fdd�	Z�fdd�Ze�dd��Ze�dd	��Ze�d
  21  d��Zdd
  22  �Z	dd�Z
  23  dd�Zdd�Zdd�Z
  24  dd�Zdd�Zdd�Zdd�Zedd��Zd d!�Zd"d#�Zed$d%��Zed&d'��ZdMd)d*�Zed+d,��Z�fd-d.�Z�fd/d0�ZdL�fd1d2�	Zd3d4�Zed5d6��Z d7d8�Z!e"fd9d:�Z#d;d<�Z$�fd=d>�Z%d?d@�Z&dAdB�Z'dCdD�Z(edEdF��Z)dGdH�Z*dNdJdK�Z+�Z,S)O�
  25  CompiledValueNcst��||�||_dSr)�superrr#)r�inference_stater#�parent_context��	__class__rrr/s
  26  zCompiledValue.__init__cs�|j��}|durt|j|���Sz|j�d�Wnty(t��|�YSw|j�	�r@ddl
  27  m}t||j|j
  28  ||�g�St|�|��S)Nr"r)�CompiledInstance)r#Zget_return_annotation�create_from_access_pathr-�execute_annotationr$�AttributeErrorr,�
  29  py__call__�is_classZjedi.inference.valuer1rr.�_execute_function)r�	arguments�return_annotationr1r/rrr53s&
  30  ���
  31  �zCompiledValue.py__call__cC�t|j|j���Sr)r2r-r#�py__class__�rrrrr;H�zCompiledValue.py__class__cs"�ft�fdd��j��D��S)Nc3��|]	}t�j|�VqdSr�r2r-��.0�accessr<rr�	<genexpr>N�
  32  �
  33  �
  34  �z*CompiledValue.py__mro__.<locals>.<genexpr>)�tupler#Zpy__mro__accessesr<rr<r�	py__mro__Ls
  35  �zCompiledValue.py__mro__cst�fdd��j��D��S)Nc3r>rr?r@r<rrrCUrDz,CompiledValue.py__bases__.<locals>.<genexpr>)rEr#�py__bases__r<rr<rrGSs�zCompiledValue.py__bases__cC�
  36  |j��Sr)r#�get_qualified_namesr<rrrrIZ�
  37  z!CompiledValue.get_qualified_namescCrHr)r#�
  38  py__bool__r<rrrrK]rJzCompiledValue.py__bool__cCrHr)r#r6r<rrrr6`rJzCompiledValue.is_classcCrHr)r#�is_functionr<rrrrLcrJzCompiledValue.is_functioncCrHr)r#�	is_moduler<rrrrMfrJzCompiledValue.is_modulecC�dS)NTrr<rrr�is_compiledi�zCompiledValue.is_compiledcCrN)NFrr<rrr�is_stublrPzCompiledValue.is_stubcCrHr)r#�is_instancer<rrrrRorJzCompiledValue.is_instancecCrHr)r#�	py__doc__r<rrrrSrrJzCompiledValue.py__doc__c
  39  cs��z|j��}Wn;tyC|��\}}|sg}n|�d�}|j��r*|�dd�|D]}|���d�\}}}t	|||�Vq,YdSw|D]}	t
  40  ||	�VqFdS)N�,rr�=)r#Zget_signature_params�
  41  ValueError�_parse_function_doc�split�ismethoddescriptor�insert�strip�	partition�UnresolvableParamName�SignatureParamName)
  42  rZsignature_params�
  43  params_str�ret�tokens�p�name�_�default�signature_paramrrr�get_param_namesus$�
  44  
  45  ���zCompiledValue.get_param_namescCs|��\}}t||�gSr)rWr)rrdZ
  46  return_stringrrr�get_signatures�szCompiledValue.get_signaturescCsd|jj|j��fS�Nz<%s: %s>)r0r!r#�get_reprr<rrr�__repr__�szCompiledValue.__repr__cCs|��}|dur
  47  dSt|�S)N)�rl)rSrW)r�docrrrrW�sz!CompiledValue._parse_function_doccCrHr)r#Zget_api_typer<rrr�api_type�rzCompiledValue.api_typeFccs�|�|�VdSr)�_ensure_one_filter)rrRZorigin_scoperrr�get_filters�s�zCompiledValue.get_filterscCst|j||�Sr)�CompiledValueFilterr-)rrRrrrro�sz CompiledValue._ensure_one_filterc	s�tttt��,z
  48  |jj||jjd�}Wnty*t	��|�YWd�SwWd�n1s5wY|durDt	��|�St
  49  t|j|�g�S�N)�safe)r�
  50  IndexError�KeyError�	TypeErrorr#�py__simple_getitem__r-�allow_unsafe_executionsr4r,rr2)r�indexrBr/rrrw�s
  51  ����z"CompiledValue.py__simple_getitem__cs6�j��}|durt��||�St�fdd�|D��S)Nc3r>rr?r@r<rrrC�rDz.CompiledValue.py__getitem__.<locals>.<genexpr>)r#Zpy__getitem__all_valuesr,�
  52  py__getitem__r)rZindex_value_set�contextualized_nodeZall_access_pathsr/r<rrz�s
  53  �zCompiledValue.py__getitem__c#sT�|j��st��|�EdH|j��}|durdS|D]}tt|j|��VqdSr)r#Zhas_iterr,�
  54  py__iter__Zpy__iter__listrr2r-)rr{Zaccess_path_listrBr/rrr|�s�
  55  
  56  �zCompiledValue.py__iter__cCrHr)r#�
  57  py__name__r<rrrr}�rJzCompiledValue.py__name__cCs$|��}|dur
  58  |j��}t||�Sr)r}r#rj�CompiledValueName�rrcrrrrc�s
  59  
  60  zCompiledValue.namec	cs��ddlm}ddlm}|jdkrdS|��d��D]&}z
  61  |jjj	�
  62  |�Wn	ty1Yqw||j|�}|j�||�EdHq|�
  63  |�EdHdS)Nr)�
  64  docstrings��builtin_from_name�function�)Zjedi.inferencer��jedi.inference.compiledr�rnrWrXr-�builtins_moduler#r$r4�executeZinfer_return_types)r�paramsr�r�rcZbltn_objrrrr7�s�
  65  �zCompiledValue._execute_functioncCs.z|j��WSty|tkr�|YSwr)r#�get_safe_valuerVr)rrerrrr��s�zCompiledValue.get_safe_valuecCs8ztt|j|j�|j|��g�WStytYSwr)rr2r-r#�execute_operationrvr)r�other�operatorrrrr��s
  66  ��zCompiledValue.execute_operationcs��j��dkrt�g�S�j��\}}�fdd�|D��|dkr*t�dd��D��S|r>t�fdd��jj�|�D����St	���S)N�Nonecsg|]}tt�j|�g��qSr)rr2r-)rA�pathr<rr�
  67  <listcomp>�s��z4CompiledValue.execute_annotation.<locals>.<listcomp>�Unioncss�|]}|��VqdSr)r3)rA�argrrrrC�s�z3CompiledValue.execute_annotation.<locals>.<genexpr>csg|]}|����qSr)Z
  68  with_generics�rA�v)r8rrr�s��)
  69  r#rjrZget_annotation_name_and_argsZ	from_setsr-Z
  70  typing_moduleZpy__getattribute__r3r,)rrc�argsr/)r8rrr3�s
  71  
  72  ���
  73  z CompiledValue.execute_annotationcCr:r)r2r-r#�negater<rrrr�
  74  �zCompiledValue.negatecC�tSr�rr<rrr�get_metaclasses
  75  rPzCompiledValue.get_metaclassescC�t|�Sr)rr<rrr�_as_context�zCompiledValue._as_contextcCrHr)r#Zget_array_typer<rrr�
  76  array_typerzCompiledValue.array_typecs�fdd��j��D�S)Ncsg|]}t�j|��qSrr?)rA�kr<rrr�s
  77  ��z0CompiledValue.get_key_values.<locals>.<listcomp>)r#Z
  78  get_key_pathsr<rr<r�get_key_valuess
  79  �zCompiledValue.get_key_valuesTcCs|j��dvr	dSdS)N)r�z<class 'NoneType'>r�)r#rj)rZadd_class_inforrr�
  80  get_type_hintszCompiledValue.get_type_hintr)FN)T)-r!r(r)rr5rr;rFrGrIrKr6rLrMrOrQrRrSrrgrhrkrrW�propertyrnrprorwrzr|r}rcr7rr�r�r3r�r�r�r�r�r��
  81  __classcell__rrr/rr+.s\
  82  
  83  
  84  
  85  
  86  
  87  
  88  
  89  
  90  	
  91  r+c@sFeZdZdZdd�Zdd�Zdd�Zedd	��Zd
  92  e	e
  93  fdd�ZdS)
  94  �CompiledModuleNcCr�r)rr<rrrr�&r�zCompiledModule._as_contextcCrHr)r#�
  95  py__path__r<rrrr�)rJzCompiledModule.py__path__cCs|��duSr)r�r<rrr�
  96  is_package,�zCompiledModule.is_packagecCs"|��}|dur
  97  dSt|�d��S)Nr�.)r}rErXrrrr�string_names/szCompiledModule.string_names�returncCrHr)r#�
  98  py__file__r<rrrr�7rJzCompiledModule.py__file__)r!r(r)Zfile_ior�r�r�r�r�rrr�rrrrr�#s
  99  r�c@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
 100  �Zedd��Z	d
 101  d�Z
 102  edd��ZdS)�CompiledNamecCs&||_|��|_||_||_||_dSr)�_inference_state�
 103  as_contextr.�
 104  _parent_value�string_name�
 105  is_descriptor)rr-Zparent_valuercr�rrrr<s
 106  
 107  
 108  zCompiledName.__init__cCs|����Sr)�infer_compiled_valuerSr<rrrrSCr�zCompiledName.py__doc__cCs"|j��}|durdS||jfSr)r.rIr�)rZparent_qualified_namesrrr�_get_qualified_namesFs
 109  z!CompiledName._get_qualified_namescCs$|j}|��s|��r|j��SdSr)r.rMr6�	get_value)r�contextrrr�get_defining_qualified_valueLs
 110  z)CompiledName.get_defining_qualified_valuecCs8z|jj}Wntyd}Ynwd|jj||jfS)Nz
 111  <%s: (%s).%s>)r.rcr4r0r!r�rrrrrkSs�zCompiledName.__repr__cCs|jrdS|��jS)Nr%)r�r�rnr<rrrrnZs
 112  zCompiledName.api_typecCst|��g�Sr)rr�r<rrr�inferc�zCompiledName.infercCst|j|j|j�Sr)�create_from_namer�r�r�r<rrrr�fr=z!CompiledName.infer_compiled_valueN)
 113  r!r(r)rrSr�r�rkr�rnr�rr�rrrrr�;s
 114  r�c@s8eZdZdd�Zedd��Zdd�Zdd�Zd	d
 115  �ZdS)r^cCs|j|_||_dSr)r.�_signature_param)r�compiled_valuerfrrrrl�
 116  zSignatureParamName.__init__cCs|jjSr)r�rcr<rrrr�pszSignatureParamName.string_namecCsB|��|j}|jjr|d|jj7}|jjr|d|jj7}|S)Nz: rU)Z_kind_stringr�r��has_annotationZannotation_string�has_defaultZdefault_string)r�srrr�	to_stringtszSignatureParamName.to_stringcCstt|jj�Sr)�getattrrr�Z	kind_namer<rrr�get_kind|r�zSignatureParamName.get_kindcCsL|j}|jj}t}|jrtt||j�g�}|jr$t||j	�}||�
 117  �O}|Sr)r�r.r-rr�rr2rer��
 118  annotationZexecute_with_values)rrbr-�valuesr�rrrr�szSignatureParamName.inferN)	r!r(r)rr�r�r�r�r�rrrrr^ks
 119  r^c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
 120  r]cCs|j|_||_||_dSr)r.r��_default)rr�rcrerrrr�s
 121  zUnresolvableParamName.__init__cCstjSr)r�POSITIONAL_ONLYr<rrrr��szUnresolvableParamName.get_kindcCs|j}|jr
 122  |d|j7}|S)NrU)r�r�)r�stringrrrr��szUnresolvableParamName.to_stringcCr�rr�r<rrrr��rPzUnresolvableParamName.inferN)r!r(r)rr�r�r�rrrrr]�s
 123  r]c@seZdZdd�ZdS)r~cCs||_||_|j|_dSr)r��_valuer.)r�valuercrrrr�szCompiledValueName.__init__N)r!r(r)rrrrrr~�sr~c@s eZdZdZdd�Zdd�ZdS)�EmptyCompiledNamez�
 124      Accessing some names will raise an exception. To avoid not having any
 125      completions, just give Jedi the option to return this object. It infers to
 126      nothing.
 127      cCs|j|_||_dSr)r�r.r�)rr-rcrrrr�r�zEmptyCompiledName.__init__cCr�rr�r<rrrr��rPzEmptyCompiledName.inferN)r!r(r)r*rr�rrrrr��sr�c@sTeZdZddd�Zdd�Zddd�Zeddd�d	d
 128  ��Zdd�Zd
 129  d�Z	dd�Z
 130  dS)rqFcCs||_||_||_dSr)r�r�rR)rr-r�rRrrrr�s
 131  zCompiledValueFilter.__init__cs6|jj�|jj�|j|��fdd��fdd�dd�S)Ncs�j|�d�Srr)Zis_allowed_getattr�rc�r#rsrr�<lambda>�sz)CompiledValueFilter.get.<locals>.<lambda>cs|���vSr)�dirr�)r#rrr��sT)�check_has_attribute)r�r#r�rx�_getrrr�r�get�s
 132  
 133  �zCompiledValueFilter.getc	s�|��\}}}|durt|j|���}|r�fdd�|D�S|r$|s$gS|s(|s4|jjs4|j�dd�gS|jr=|��s=gS|j�|d�gS)zU
 134          To remove quite a few access calls we introduced the callback here.
 135          Ncsg|]}t|���qSr)r~r�r�rrr��sz,CompiledValueFilter._get.<locals>.<listcomp>T)�is_empty�r�)r2r�r3rx�_get_cached_namerR)	rrcZallowed_getattr_callbackZin_dir_callbackr�Z
 136  has_attributer�Zproperty_return_annotationr�rr�rr��s*
 137  ����zCompiledValueFilter._getr�cCs|rt|j|�S|j||d�S)Nr�)r�r��_create_name)rrcr�r�rrrr��sz$CompiledValueFilter._get_cached_namec	s|ddlm}g}|jj��\}��D]}||�|�fdd��fdd��7}q|js<|r<||jd���D]}||�	�7}q3|S)Nrr�cs�|Srrr��Z	dir_infosrrr���z,CompiledValueFilter.values.<locals>.<lambda>cs|�vSrrr�r�rrr��r��type)
 138  r�r�r�r#Z
 139  get_dir_infosr�rRr�rpr�)rr��namesZneeds_type_completionsrc�filterrr�rr��s
 140  
 141  �
 142  zCompiledValueFilter.valuescCst|j|j||�Sr)r�r�r�)rrcr�rrrr��s�z CompiledValueFilter._create_namecCsd|jj|jfSri)r0r!r�r<rrrrkr�zCompiledValueFilter.__repr__N)F)r!r(r)rr�r�rr�r�r�rkrrrrrq�s
 143  
 144  
 145  rq�float�str�int�dict)zfloating point number�	character�integer�
 146  dictionaryr�c	CsJz9d}|�d�}t||d��D]\}}|dkr|d7}n|dkr%|d8}|dkr/||}nq||d|�}WnttfyMt�d�d}d}Ynwdd	�}	t�d||�\}}|dkranqS|�dd
 147  �}t�	d|||d��}	|	dur~d}
 148  ||
 149  fS||	�
 150  �}t�d�}|�||��
 151  d���}
 152  t�dd|
 153  �}
 154  t�|
 155  |
 156  �}
 157  ||
 158  fS)z�
 159      Takes a function and returns the params and return value as a tuple.
 160      This is nothing more than a docstring parser.
 161  
 162      TODO docstrings like utime(path, (atime, mtime)) and a(b [, b]) -> None
 163      TODO docstrings like 'tuple of integers'
 164      r�(Nr��)zno brackets found - no paramrlcSsH|�d��d�}t|�D]\}}|rd|vr||d7<qd�|�S)Nr�rTrUz=None)�grouprX�	enumerate�join)�mr��i�arrr�change_options,s�
 165  z+_parse_function_doc.<locals>.change_optionsTz ?\[([^\[\]]+)\]�-rdz-[>-]* �z
 166  (,\n|[^\n-])+z[nN]ew (.*)z\1())ryr�rV�UnboundLocalErrorrZdbg�re�subn�replace�search�end�compile�matchr�r[�sub�docstr_defaultsr�)rm�count�startr�r�r�Z	param_strr��changes�rr`ry�patternZret_strrrrrWsJ	
 167  
 168  �
 169  ����
 170  rWcCs@|jj|dd�}d}|D]}t|||durdn|��d�}q|S)N)re�r.)r#r$�create_cached_compiled_valuer�)r-r�rcZaccess_pathsr��access_pathrrrr�Ks�r�csd�fdd�	}|S)z5The cache doesn't care about keyword vs. normal args.Ncs�|||�Srr)r-�objr.�r rr�wrapperZr�z'_normalize_create_args.<locals>.wrapperrr)r rrr�r�_normalize_create_argsXsrcCs6d}|jD]\}}t|||durdn|��d�}q|S)Nr�)Zaccessesr�r�)r-r�r�rcrBrrrr2_s�r2cCs,t|t�rJ�|durt}nt}||||�Sr)�
 171  isinstancer+r�)r-r#r.�clsrrrr�js
 172  r�)6r*r��	functoolsr�inspectr�pathlibr�typingrZjedirZjedi.inference.utilsrZ
 173  jedi.cacherZjedi.inference.filtersr	Zjedi.inference.namesr
 174  rrZjedi.inference.base_valuer
 175  rrZjedi.inference.lazy_valuerZjedi.inference.compiled.accessrZjedi.inference.cacherZjedi.inference.helpersrZjedi.inference.signaturerZjedi.inference.contextrrrr+r�r�r^r]r~r�rqr�rWr�rr2r�rrrr�<module>sRv0 T�	<
 176