
    Dd-A                     B   d Z ddlmZ ddlmZmZmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZmZ ddlmZ ddlmZmZ dd	lmZmZ dd
lmZmZmZ ddlmZ ddlmZ ddl m!Z!m"Z" ddl#m$Z$  G d de          Z% G d de          Z& G d d          Z' G d de'ee	          Z(dS )a  
Like described in the :mod:`parso.python.tree` module,
there's a need for an ast like module to represent the states of parsed
modules.

But now there are also structures in Python that need a little bit more than
that. An ``Instance`` for example is only a ``Class`` before it is
instantiated. This class represents these cases.

So, why is there also a ``Class`` class here? Well, there are decorators and
they change classes in Python 3.

Representation modules also define "magic methods". Those methods look like
``py__foo__`` and are typically mappable to the Python equivalents ``__call__``
and others. Here's a list:

====================================== ========================================
**Method**                             **Description**
-------------------------------------- ----------------------------------------
py__call__(arguments: Array)           On callable objects, returns types.
py__bool__()                           Returns True/False/None; None means that
                                       there's no certainty.
py__bases__()                          Returns a list of base classes.
py__iter__()                           Returns a generator of a set of types.
py__class__()                          Returns the class of an instance.
py__simple_getitem__(index: int/str)   Returns a a set of types of the index.
                                       Can raise an IndexError/KeyError.
py__getitem__(indexes: ValueSet)       Returns a a set of types of the index.
py__file__()                           Only on modules. Returns None if does
                                       not exist.
py__package__() -> List[str]           Only on modules. For the import system.
py__path__()                           Only on modules. For the import system.
py__get__(call_object)                 Only on instances. Simulates
                                       descriptors.
py__doc__()                            Returns the docstring for a value.
====================================== ========================================

    )debug)get_cached_parent_scopeexpr_is_dottedfunction_is_property)inference_state_method_cacheCachedMetaClass&inference_state_method_generator_cache)compiled)LazyKnownValuesLazyTreeValue)ParserTreeFilter)TreeNameDefinition	ValueName)unpack_arglistValuesArguments)ValueSetiterator_to_value_set	NO_VALUESClassContext)FunctionAndClassBase)LazyGenericManagerTupleGenericManager)plugin_managerc                   N     e Zd Z fdZed             Ze fd            Z xZS )	ClassNamec                 h    t                                          ||           || _        || _        d S N)super__init___apply_decorators_class_value)selfclass_value	tree_namename_contextapply_decorators	__class__s        :lib/python3.11/site-packages/jedi/inference/value/klass.pyr    zClassName.__init__:   s3    y111!1'    c              #      K   ddl m}  || j        j        | j        | j                  }|D ]0}| j        r#|                    d | j                  E d {V  ,|V  1d S )Nr   )tree_name_to_values)instancer$   )jedi.inference.syntax_treer,   parent_contextinference_stater%   r!   	py__get__r"   )r#   r,   inferredresult_values       r)   inferzClassName.infer?   s       	CBBBBB&&/1DdnV V % 	# 	#L% #'114TM^1__________"""""		# 	#r*   c                     t                      j        }|dk    r*| j                                        }t	          |          rdS |S )Nfunctionproperty)r   api_typer%   get_definitionr   )r#   type_
definitionr(   s      r)   r8   zClassName.api_typeL   sK     J 	"6688J#J// " "zr*   )	__name__
__module____qualname__r    r   r4   r7   r8   __classcell__r(   s   @r)   r   r   9   sy        ( ( ( ( (
 
# 
# 
#     X    r*   r   c                   @     e Zd Z	 	 d fd	Zd Zd Zd Z fdZ xZS )	ClassFilterNFc                     t                                          |                                |||           || _        || _        d S )N)until_positionorigin_scope)r   r    
as_contextr"   _is_instance)r#   r$   node_contextrD   rE   is_instancer(   s         r)   r    zClassFilter.__init__\   sS    ""$$l)% 	 	
 	
 	

 ('r*   c                        fd|D             S )Nc                 V    g | ]%}t          j        |j        j                    &S ))r$   r%   r&   r'   )r   r"   _node_contextrG   .0namer#   s     r)   
<listcomp>z.ClassFilter._convert_names.<locals>.<listcomp>g   sR     
 
 
   -!/%)%6!6	  
 
 
r*    )r#   namess   ` r)   _convert_nameszClassFilter._convert_namesf   s0    
 
 
 
  
 
 
 	
r*   c                 v    | j         }|/|| j        k    s|| j        k    rdS t          | j        |          }|/dS )NTF)_origin_scope_parser_scoper/   r   _parso_cache_node)r#   nodes     r)   _equals_origin_scopez ClassFilter._equals_origin_scopep   s[    ! 	It)) TT5H-H t*4+A4HHD  	I ur*   c                 l   | j         se|                                }|O|j        dk    rD|j        d         }|j        dk    r,d|j        d                                         vrd|j        vrdS |j                            d           p-|j                            d          p|                                 S )N	expr_stmt   	annassignClassVar=F__)	rG   r9   typechildrenget_codevalue
startswithendswithrY   )r#   rO   r[   r]   s       r)   _access_possiblezClassFilter._access_possiblex   s    
   		%++--I %;)F %%.q1	>[0 % ");A)>)G)G)I)II % #9+= =%$u :((... +$*2E2Ed2K2K +((**	+r*   c                 d     t                                          |          } fd|D             S )Nc                 >    g | ]}                     |          |S rQ   )rg   rM   s     r)   rP   z'ClassFilter._filter.<locals>.<listcomp>   s,    FFF$*?*?*E*EFFFFr*   )r   _filter)r#   rR   r(   s   ` r)   rj   zClassFilter._filter   s3    &&FFFFFFFFr*   )NNNF)	r<   r=   r>   r    rS   rY   rg   rj   r?   r@   s   @r)   rB   rB   [   s        FJ05( ( ( ( ( (
 
 
  + + +(G G G G G G G G Gr*   rB   c                       e Zd Zd Zd Zd Zd Zed             Zd Z	 e
            d             Z	 	 ddZd Zd ZddZ ed	          d             Zd Zd Zd ZdS )
ClassMixinc                     dS NTrQ   r#   s    r)   is_classzClassMixin.is_class       tr*   c                     dS rn   rQ   ro   s    r)   is_class_mixinzClassMixin.is_class_mixin   rq   r*   c                     ddl m} ddlm} |                                 rt           ||           g          S t           || j        | j        | |          g          S )Nr   )TreeInstance)	TypedDict)jedi.inference.valueru   jedi.inference.gradual.typingrv   is_typeddictr   r0   r/   )r#   	argumentsru   rv   s       r)   
py__call__zClassMixin.py__call__   s|    555555;;;;;; 	/YYt__-...d&:D<OQUW`aabcccr*   c                 6    t          j        | j        d          S )Nra   )r
   builtin_from_namer0   ro   s    r)   py__class__zClassMixin.py__class__   s    )$*>GGGr*   c                 6    t          | | j        j                  S r   )r   	tree_noderO   ro   s    r)   rO   zClassMixin.name   s    t~2333r*   c                     | j         j        S r   )rO   string_namero   s    r)   
py__name__zClassMixin.py__name__   s    y$$r*   c              #   &  K   | g}| V  |                                  D ]r}|                                D ][}	 |j        } |            D ]}||vr|                    |           |V   5# t          $ r 	 t          j        d| |           Y Xw xY wsd S )Nz$Super class of %s is not a class: %s)py__bases__r4   	py__mro__appendAttributeErrorr   warning)r#   mrolazy_clscls
mro_methodcls_news         r)   r   zClassMixin.py__mro__   s      f


 ((** 	* 	*H  ~~'' * **!$J $.:<< * *"#- *JJw///")MMM* & U U U	 M"H$PSTTTTTU*	* 	*s   A))!BBNFTc              #     K   |r2|                                  }|r|                     ||          E d {V  |                                 D ]Z}|                                r|                    |          E d {V  3t          | |                                ||          V  [|s|rddlm}  || j	        d          }t          |t                    sJ || k    rwt          g           }	|                    |	          D ]T}
|
                                }t          |d            t          |d            t          |d           }|J |V  Od S d S d S d S )N)rI   )rH   rE   rI   r   )r}   ra   )get_metaclassesget_metaclass_filtersr   is_compiledget_filtersrB   rF   jedi.inference.compiledr}   r0   
isinstance
ClassValuer   r{   next)r#   rE   rI   include_metaclassesinclude_type_when_classmetaclassesr   r}   r:   argsr-   instance_filtersxs                r)   r   zClassMixin.get_filters   s      	P..00K P55k;OOOOOOOOO>>## 	 	C   ??{?CCCCCCCCCC!s~~'7'7!- +      
  	6 	AAAAAA%%d&:FCCEeZ00000}  'r** % 0 0 6 6  H'/';';'='=$)4000)4000-t44A(((GGGG!	 	 	 	 
 r*   c                                                       }|r                     |          }|r|S t          g           }                     |                              d          } fd|                                D             S )Nr    c                 :    g | ]}|                               S rQ   )bind)rN   sigr#   s     r)   rP   z-ClassMixin.get_signatures.<locals>.<listcomp>   s#    FFF3FFFr*   )r   get_metaclass_signaturesr   r{   py__getattribute__get_signatures)r#   r   sigsr   
init_funcss   `    r)   r   zClassMixin.get_signatures   s     **,, 	00==D r""__T**==jII
FFFF**C*C*E*EFFFFr*   c                      t          |           S r   r   ro   s    r)   _as_contextzClassMixin._as_context   s    D!!!r*   c                 \    |rd|                                  z  S |                                  S )NzType[%s])r   )r#   add_class_infos     r)   get_type_hintzClassMixin.get_type_hint   s/     	2 1 111   r*   defaultc                 J   ddl m} |                                 D ]}t          |t                    s dS |j        }t          |          s dS |                                D ]?}t          ||          r  dS 	 |j        } |            r  dS -# t          $ r Y   dS w xY wdS )Nr   )TypedDictClassFT)
rx   r   r   r   r   datar   r4   ry   r   )r#   r   r   r   r   methods         r)   ry   zClassMixin.is_typeddict  s     	A@@@@@((** 	$ 	$Hh66 uu I "),, uu~~'' $ $c>22  444	$ -F vxx $#ttt$ & ! ! ! !5555	!$ us   9B
BBc                      ddl m |s$t          j        d           t	           g          S t	           fd|D                       S )Nr   GenericClassz:Class indexes inferred to nothing. Returning class insteadc              3   X   K   | ]$} t          j        |                     V  %dS ))context_of_indexindex_valueN)r   context)rN   r   r   contextualized_noder#   s     r)   	<genexpr>z+ClassMixin.py__getitem__.<locals>.<genexpr>%  sc       	
 	
  L"%8%@ +   	
 	
 	
 	
 	
 	
r*   )jedi.inference.gradual.baser   r   r   r   )r#   index_value_setr   r   s   ` `@r)   py__getitem__zClassMixin.py__getitem__   s    <<<<<< 	$MVWWWTF### 	
 	
 	
 	
 	
 	
  /	
 	
 	
 	
 	
 		
r*   c                 @    ddl m}  || t          |                    S )Nr   r   )r   r   r   )r#   generics_tupler   s      r)   with_genericszClassMixin.with_generics0  s6    <<<<<<|//
 
 	
r*   c                      ddl m}  fd}r<t           | t          t	           |                                          g          S t           h          S )Nr   r   c               3      K                                    D ]1}                     |                                 t                    V  2dS )aa  
            The TypeVars in the resulting classes have sometimes different names
            and we need to check for that, e.g. a signature can be:

            def iter(iterable: Iterable[_T]) -> Iterator[_T]: ...

            However, the iterator is defined as Iterator[_T_co], which means it has
            a different type var name.
            N)list_type_varsgetr   r   )type_varr#   type_var_dicts    r)   remap_type_varsz3ClassMixin.define_generics.<locals>.remap_type_vars:  s]       !//11 J J#''(;(;(=(=yIIIIIIJ Jr*   )r   r   r   r   tuple)r#   r   r   r   s   ``  r)   define_genericszClassMixin.define_generics7  s    <<<<<<	J 	J 	J 	J 	J 	J  	\\#E//*;*;$<$<==      r*   )NFTT)T)r<   r=   r>   rp   rs   r{   r~   r7   rO   r   r	   r   r   r   r   r   r   ry   r   r   r   rQ   r*   r)   rl   rl      sO           d d dH H H 4 4 X4% % % ,+--* * .-*@ :?FJ       DG G G" " "! ! ! !
 "!%000  10:
 
 
 
 
 
         r*   rl   c                       e Zd ZdZ e            d             Zd Z ed          d             Z ej	                    d             Z
 ee          d             Z ej	                    d	             Zd
S )r   classc                     g }| j                                         }|g S t          |          D ];\  }}|rddlm}  || j        |          D ]}||vr|                    |           <|S )Nr   )find_unknown_type_vars)r   get_super_arglistr   !jedi.inference.gradual.annotationr   r/   r   )r#   foundargliststarsrX   r   r   s          r)   r   zClassValue.list_type_varsR  s    .2244 	I)'22 	+ 	+KE4 PPPPPP2243FMM + +5( +LL***+ r*   c                     | j                                         }|r'ddlm} |                    | j        | j        |          S d S )Nr   )rz   )r   r   jedi.inferencerz   TreeArgumentsr0   r/   )r#   r   rz   s      r)   _get_bases_argumentszClassValue._get_bases_argumentsd  sT    .2244 	_000000**4+?ATV]^^^tr*   rQ   r   c                 2   |                                  }|"d |                                D             }|r|S |                                 dk    r| j                                        rg S t          | j        j                            d                    gS )Nc                     g | ]	\  }}||
S r   rQ   rN   keyrd   s      r)   rP   z*ClassValue.py__bases__.<locals>.<listcomp>o  s!    HHHZS%CH5HHHr*   object)	r   unpackr   r/   is_builtins_moduler   r0   builtins_moduler   )r#   r   lsts      r)   r   zClassValue.py__bases__k  s    ((** 	HH4;;==HHHC 
??( 	'::<<	I 0CCHMM
 
  	r*   c                 0    t          j        d|           g S )NzUnprocessed metaclass %s)r   r   )r#   r   rI   s      r)   r   z ClassValue.get_metaclass_filtersz  s    0+>>>	r*   c                    |                                  }|Yd |                                D             }t          j        d |D                       }t          d |D                       }|r|S |                                 D ]I}|                                D ]2}|                                r|                                }|r|c c S 3Jt          S )Nc                 $    g | ]\  }}|d k    |S 	metaclassrQ   r   s      r)   rP   z.ClassValue.get_metaclasses.<locals>.<listcomp>  s&    MMM:3#:LMMMMr*   c              3   >   K   | ]}|                                 V  d S r   )r4   )rN   
lazy_values     r)   r   z-ClassValue.get_metaclasses.<locals>.<genexpr>  s.      ,T,TJZ-=-=-?-?,T,T,T,T,T,Tr*   c              3   B   K   | ]}|                                 |V  d S r   )rp   )rN   ms     r)   r   z-ClassValue.get_metaclasses.<locals>.<genexpr>  s/      "J"JQZZ\\"J1"J"J"J"J"J"Jr*   )	r   r   r   	from_setsr   r4   rp   r   r   )r#   r   r   r   	lazy_baserd   valuess          r)   r   zClassValue.get_metaclasses  s    ((** 	#MMMMMA",,T,TRS,T,T,TTTK""J"Jk"J"J"JJJK #""))++ 	& 	&I"** & &>>## &"2244F &%	&
 r*   c                     g S r   rQ   )r#   r   s     r)   r   z#ClassValue.get_metaclass_signatures  s    	r*   N)r<   r=   r>   r8   r   r   r   r   r   decorater   r   r   r   rQ   r*   r)   r   r   O  s        H!!##  $#"   "!"---  .- ^   "!)444  54" ^    r*   r   r   N))__doc__jedir   jedi.parser_utilsr   r   r   jedi.inference.cacher   r   r	   r   r
   jedi.inference.lazy_valuer   r   jedi.inference.filtersr   jedi.inference.namesr   r   jedi.inference.argumentsr   r   jedi.inference.base_valuer   r   r   jedi.inference.contextr   jedi.inference.value.functionr   jedi.inference.gradual.genericsr   r   jedi.pluginsr   r   rB   rl   r   rQ   r*   r)   <module>r      sN  % %L               + + + + + + + + + + # # # # # # D D D D D D D D 3 3 3 3 3 3 > > > > > > > > D D D D D D D D          / / / / / / > > > > > > S S S S S S S S ' ' ' ' ' '    "   D3G 3G 3G 3G 3G" 3G 3G 3Gl{  {  {  {  {  {  {  { |D D D D D1_ D D D D D Dr*   