Format: application/x-python-code
⬇ Download File (13.5 KB)
   1  o
   2  
   3  �hD>�@sdZddlmZddlmZmZmZddlmZm	Z	m
   4  Z
   5  ddlmZddl
   6  mZmZddlmZddlmZmZdd	lmZmZdd
   7  lmZmZmZddlmZddlmZdd
   8  l m!Z!m"Z"ddl#m$Z$Gdd�de�Z%Gdd�de�Z&Gdd�d�Z'Gdd�de'ee	d�Z(dS)a
   9  Like described in the :mod:`parso.python.tree` module,
  10  there's a need for an ast like module to represent the states of parsed
  11  modules.
  12  
  13  But now there are also structures in Python that need a little bit more than
  14  that. An ``Instance`` for example is only a ``Class`` before it is
  15  instantiated. This class represents these cases.
  16  
  17  So, why is there also a ``Class`` class here? Well, there are decorators and
  18  they change classes in Python 3.
  19  
  20  Representation modules also define "magic methods". Those methods look like
  21  ``py__foo__`` and are typically mappable to the Python equivalents ``__call__``
  22  and others. Here's a list:
  23  
  24  ====================================== ========================================
  25  **Method**                             **Description**
  26  -------------------------------------- ----------------------------------------
  27  py__call__(arguments: Array)           On callable objects, returns types.
  28  py__bool__()                           Returns True/False/None; None means that
  29                                         there's no certainty.
  30  py__bases__()                          Returns a list of base classes.
  31  py__iter__()                           Returns a generator of a set of types.
  32  py__class__()                          Returns the class of an instance.
  33  py__simple_getitem__(index: int/str)   Returns a a set of types of the index.
  34                                         Can raise an IndexError/KeyError.
  35  py__getitem__(indexes: ValueSet)       Returns a a set of types of the index.
  36  py__file__()                           Only on modules. Returns None if does
  37                                         not exist.
  38  py__package__() -> List[str]           Only on modules. For the import system.
  39  py__path__()                           Only on modules. For the import system.
  40  py__get__(call_object)                 Only on instances. Simulates
  41                                         descriptors.
  42  py__doc__()                            Returns the docstring for a value.
  43  ====================================== ========================================
  44  
  45  �)�debug)�get_cached_parent_scope�expr_is_dotted�function_is_property)�inference_state_method_cache�CachedMetaClass�&inference_state_method_generator_cache)�compiled)�LazyKnownValues�
  46  LazyTreeValue)�ParserTreeFilter)�TreeNameDefinition�	ValueName)�unpack_arglist�ValuesArguments)�ValueSet�iterator_to_value_set�	NO_VALUES��ClassContext)�FunctionAndClassBase)�LazyGenericManager�TupleGenericManager)�plugin_managercs8eZdZ�fdd�Zedd��Ze�fdd��Z�ZS)�	ClassNamecst��||�||_||_dS�N)�super�__init__�_apply_decorators�_class_value)�self�class_value�	tree_name�name_context�apply_decorators��	__class__��Pc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/value/klass.pyr:s
  47  zClassName.__init__ccsT�ddlm}||jj|j|j�}|D]}|jr$|jd|jd�EdHq|VqdS)Nr)�tree_name_to_values)�instancer!)Zjedi.inference.syntax_treer)�parent_context�inference_stater"rZ	py__get__r)r r)�inferredZresult_valuer'r'r(�infer?s���zClassName.infercs6t�j}|dkr|j��}|dur|St|�rdS|S)N�function�property)r�api_typer"Zget_definitionr)r �type_Z
  48  definitionr%r'r(r1Ls
  49  zClassName.api_type)	�__name__�
  50  __module__�__qualname__rrr.r0r1�
  51  __classcell__r'r'r%r(r9s
  52  rcsFeZdZ		d
  53  �fdd�	Zdd�Zdd�Zd	d
  54  �Z�fdd�Z�ZS)�ClassFilterNFcs(t�j|��|||d�||_||_dS)N)�until_position�origin_scope)rr�
  55  as_contextr�_is_instance)r r!�node_contextr8r9�is_instancer%r'r(r^s�
  56  zClassFilter.__init__cs�fdd�|D�S)Ncs$g|]}t�j|�j�jd��qS))r!r"r#r$)rrZ
  57  _node_contextr;��.0�name�r r'r(�
  58  <listcomp>is���z.ClassFilter._convert_names.<locals>.<listcomp>r'�r �namesr'rAr(�_convert_nameshs
  59  �zClassFilter._convert_namescCs>|j}|dur||jks||jkrdSt|j|�}|dusdS)NTF)Z
  60  _origin_scopeZ
  61  _parser_scoper+rZ_parso_cache_node)r �noder'r'r(�_equals_origin_scopers�z ClassFilter._equals_origin_scopecCs"|j�d�p|j�d�p|��S)N�__)�value�
  62  startswith�endswithrG)r r@r'r'r(�_access_possiblezs�zClassFilter._access_possiblecst��|�}�fdd�|D�S)Ncsg|]	}��|�r|�qSr')rLr>rAr'r(rB�sz'ClassFilter._filter.<locals>.<listcomp>)r�_filterrCr%rAr(rMszClassFilter._filter)NNNF)	r3r4r5rrErGrLrMr6r'r'r%r(r7]s�
  63  
  64  r7c@s�eZdZdd�Zdd�Zdd�Zdd�Zed	d
  65  ��Zdd�Z	e
  66  �d
  67  d��Z		d#dd�Zdd�Z
  68  dd�Zd$dd�Zedd�dd��Zdd�Zdd �Zd!d"�ZdS)%�
  69  ClassMixincC�dS�NTr'rAr'r'r(�is_class��zClassMixin.is_classcCrOrPr'rAr'r'r(�is_class_mixin�rRzClassMixin.is_class_mixincCsFddlm}ddlm}|��rt||�g�St||j|j||�g�S)Nr)�TreeInstance)�	TypedDict)Zjedi.inference.valuerT�jedi.inference.gradual.typingrU�is_typeddictrr,r+)r �	argumentsrTrUr'r'r(�
  70  py__call__�s
  71  zClassMixin.py__call__cCst�|jd�S)N�type)r	�builtin_from_namer,rAr'r'r(�py__class__�szClassMixin.py__class__cCst||jj�Sr)r�	tree_noder@rAr'r'r(r@�szClassMixin.namecCs|jjSr)r@Zstring_namerAr'r'r(�
  72  py__name__��zClassMixin.py__name__c
  73  cs��|g}|V|��D]2}|��D]+}z|j}Wnty)	t�d||�Yqw|�D]}||vr;|�|�|Vq-qqdS)Nz$Super class of %s is not a class: %s)�py__bases__r.�	py__mro__�AttributeErrorr�warning�append)r �mro�lazy_cls�clsZ
  74  mro_methodZcls_newr'r'r(ra�s&�
  75  
  76  �
  77  
  78  ����zClassMixin.py__mro__NFTc
  79  cs��|r|��}|r|�||�EdH|��D]}|��r&|j|d�EdHqt||��||d�Vq|su|rwddlm}||j	d�}t
  80  |t�sIJ�||krytg�}	|�
  81  |	�D]$}
  82  |
  83  ��}t|d�t|d�t|d�}|dusqJ�|VqVdSdSdSdS)N)r=)r<r9r=r)r[rZ)�get_metaclasses�get_metaclass_filtersraZis_compiled�get_filtersr7r:Zjedi.inference.compiledr[r,�
  84  isinstance�
  85  ClassValuerrY�next)
  86  r r9r=Zinclude_metaclassesZinclude_type_when_class�metaclassesrgr[r2�argsr*Zinstance_filters�xr'r'r(rj�s:�
  87  �
  88  
  89  
  90  �zClassMixin.get_filterscsL���}|r��|�}|r|Stg�}��|��d�}�fdd�|��D�S)Nrcsg|]}|����qSr')�bind)r?�sigrAr'r(rB�sz-ClassMixin.get_signatures.<locals>.<listcomp>)rh�get_metaclass_signaturesrrY�py__getattribute__�get_signatures)r rnZsigsroZ
  91  init_funcsr'rAr(ru�s
  92  zClassMixin.get_signaturescCst|�SrrrAr'r'r(�_as_context�r_zClassMixin._as_contextcCs|rd|��S|��S)NzType[%s])r^)r Zadd_class_infor'r'r(�
  93  get_type_hint�szClassMixin.get_type_hint��defaultc
  94  Cs�ddlm}|��D]=}t|t�sdS|j}t|�sdS|��D]$}t||�r-dSz|j}Wnt	y>YdSw|�rFdSq"q
  95  dS)Nr)�TypedDictClassFT)
  96  rVrzr`rkr�datarr.rWrb)r rzrfr]rg�methodr'r'r(rW�s(
  97  
  98  
  99  
 100  ���
 101  zClassMixin.is_typeddictcs>ddlm�|st�d�t�g�St���fdd�|D��S)Nr��GenericClassz:Class indexes inferred to nothing. Returning class insteadc3s$�|]
 102  }��t�j|d��VqdS))Zcontext_of_index�index_valueN)r�context)r?r�r~�contextualized_noder r'r(�	<genexpr>s����
 103  �z+ClassMixin.py__getitem__.<locals>.<genexpr>)�jedi.inference.gradual.baser~rrcr)r Zindex_value_setr�r'r�r(�
 104  py__getitem__s
 105  
 106  �zClassMixin.py__getitem__cCsddlm}||t|��S)Nrr})r�r~r)r Zgenerics_tupler~r'r'r(�
 107  with_generics#s
 108  �zClassMixin.with_genericscsBddlm}��fdd�}�rt|�tt|����g�St�h�S)Nrr}c3s&����D]}��|��t�VqdS)aa
 109              The TypeVars in the resulting classes have sometimes different names
 110              and we need to check for that, e.g. a signature can be:
 111  
 112              def iter(iterable: Iterable[_T]) -> Iterator[_T]: ...
 113  
 114              However, the iterator is defined as Iterator[_T_co], which means it has
 115              a different type var name.
 116              N)�list_type_vars�getr^r)�type_var�r �
 117  type_var_dictr'r(�remap_type_vars-s�
 118  �z3ClassMixin.define_generics.<locals>.remap_type_vars)r�r~rr�tuple)r r�r~r�r'r�r(�define_generics*s
 119  �
 120  zClassMixin.define_generics)NFTT)T)r3r4r5rQrSrYr\r0r@r^rrarjrurvrwrrWr�r�r�r'r'r'r(rN�s*
 121  
 122   
 123  �"
 124  
 125  rNc@sjeZdZdZe�dd��Zdd�Zedd�dd	��Ze�	�d
 126  d��Z
 127  eed�dd
 128  ��Ze�	�dd��Z
 129  dS)rl�classcCsfg}|j��}|dur
 130  gSt|�D]\}}|rqddlm}||j|�D]}||vr/|�|�q$q|S)Nr)�find_unknown_type_vars)r]�get_super_arglistrZ!jedi.inference.gradual.annotationr�r+rd)r �found�arglist�starsrFr�r�r'r'r(r�Es
 131  
 132  ��zClassValue.list_type_varscCs0|j��}|rddlm}|�|j|j|�SdS)Nr)rX)r]r��jedi.inferencerXZ
 133  TreeArgumentsr,r+)r r�rXr'r'r(�_get_bases_argumentsWs
 134  
 135  zClassValue._get_bases_argumentsr'rxcCsX|��}|durdd�|��D�}|r|S|��dkr"|j��r"gSt|jj�d��gS)NcSsg|]
 136  \}}|dur|�qSrr'�r?�keyrIr'r'r(rBb�z*ClassValue.py__bases__.<locals>.<listcomp>�object)	r��unpackr^r+Zis_builtins_moduler
 137  r,Zbuiltins_modulert)r ro�lstr'r'r(r`^s��zClassValue.py__bases__cCst�d|�gS)NzUnprocessed metaclass %s)rrc)r rnr=r'r'r(rimsz ClassValue.get_metaclass_filterscCs�|��}|dur(dd�|��D�}t�dd�|D��}tdd�|D��}|r(|S|��D]}|��D]}|��rD|��}|rD|Sq2q,tS)NcSsg|]
 138  \}}|dkr|�qS��	metaclassr'r�r'r'r(rBvr�z.ClassValue.get_metaclasses.<locals>.<listcomp>css�|]}|��VqdSr)r.)r?Z
 139  lazy_valuer'r'r(r�ws�z-ClassValue.get_metaclasses.<locals>.<genexpr>css�|]	}|��r|VqdSr)rQ)r?�mr'r'r(r�xs�)	r�r�rZ	from_setsr`r.rQrhr)r ror�rnZ	lazy_baserI�valuesr'r'r(rhrs ��zClassValue.get_metaclassescCsgSrr')r rnr'r'r(rs�sz#ClassValue.get_metaclass_signaturesN)r3r4r5r1rr�r�r`rZdecoraterirrhrsr'r'r'r(rlBs
 140  
 141  
 142  
 143  rlr�N))�__doc__ZjedirZjedi.parser_utilsrrrZjedi.inference.cacherrrr�r	Zjedi.inference.lazy_valuer
 144  rZjedi.inference.filtersrZjedi.inference.namesr
 145  rZjedi.inference.argumentsrrZjedi.inference.base_valuerrrZjedi.inference.contextrZjedi.inference.value.functionrZjedi.inference.gradual.genericsrrZjedi.pluginsrrr7rNrlr'r'r'r(�<module>s&&$'?