
    ^hD>                     "   S r SSKJr  SSKJrJrJr  SSKJrJ	r	J
r
  SSKJr  SSKJrJr  SSKJr  SSKJrJr  SS	KJrJr  SS
KJrJrJr  SSKJr  SSKJr  SSK J!r!J"r"  SSK#J$r$   " S S\5      r% " S S\5      r& " S S5      r' " S S\'\\	S9r(g)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   ^  \ rS rSrU 4S jr\S 5       r\U 4S j5       rSr	U =r
$ )	ClassName9   c                 <   > [         TU ]  X25        X@l        Xl        g N)super__init___apply_decorators_class_value)selfclass_value	tree_namename_contextapply_decorators	__class__s        T/home/james-whalen/.local/lib/python3.13/site-packages/jedi/inference/value/klass.pyr!   ClassName.__init__:   s    1!1'    c              #     #    SSK Jn  U" U R                  R                  U R                  U R                  5      nU H<  nU R
                  (       a$  UR                  S U R                  S9 S h  vN   M8  Uv   M>     g  N7f)Nr   )tree_name_to_values)instancer%   )jedi.inference.syntax_treer.   parent_contextinference_stater&   r"   	py__get__r#   )r$   r.   inferredresult_values       r*   inferClassName.infer?   sp      	C&//1D1DdnnV %L%%'114TM^M^1___""	 %_s   A,B .A>/B c                    > [         TU ]  nUS:X  a0  U R                  R                  5       nUc  U$ [	        U5      (       a  gU$ )Nfunctionproperty)r    api_typer&   get_definitionr   )r$   type_
definitionr)   s      r*   r;   ClassName.api_typeL   sG     J668J!#J// "r,   )r"   r#   )__name__
__module____qualname____firstlineno__r!   r   r6   r:   r;   __static_attributes____classcell__r)   s   @r*   r   r   9   s0    (
 
# 
#  r,   r   c                   N   ^  \ rS rSr  SU 4S jjrS rS rS rU 4S jrSr	U =r
$ )	ClassFilter]   c                 Z   > [         TU ]  UR                  5       UUUS9  Xl        XPl        g )N)until_positionorigin_scope)r    r!   
as_contextr#   _is_instance)r$   r%   node_contextrK   rL   is_instancer)   s         r*   r!   ClassFilter.__init__^   s7    ""$l)% 	 	

 ('r,   c           
          U Vs/ s H2  n[        U R                  UU R                  U R                  (       + S9PM4     sn$ s  snf )N)r%   r&   r'   r(   )r   r#   _node_contextrN   )r$   namesnames      r*   _convert_namesClassFilter._convert_namesh   sS      
  $  --!//%)%6%6!6	
  
 	
 
s   9Ac                     U R                   nUb:  XR                  :X  d  XR                  :X  a  g[        U R                  U5      nUb  M:  g)NTF)_origin_scope_parser_scoper1   r   _parso_cache_node)r$   nodes     r*   _equals_origin_scope ClassFilter._equals_origin_scoper   sL    !!)))T5H5H-H*4+A+A4HD  r,   c                     UR                   R                  S5      (       + =(       d2    UR                   R                  S5      =(       d    U R                  5       $ )N__)value
startswithendswithr]   )r$   rU   s     r*   _access_possibleClassFilter._access_possiblez   sC    ::((.. +$**2E2Ed2K +((*	+r,   c                    > [         TU ]  U5      nU Vs/ s H  o R                  U5      (       d  M  UPM     sn$ s  snf r   )r    _filterrd   )r$   rT   rU   r)   s      r*   rg   ClassFilter._filter   s4    &!&F*?*?*EFFFs   ;;)r#   rN   )NNNF)r@   rA   rB   rC   r!   rV   r]   rd   rg   rD   rE   rF   s   @r*   rH   rH   ]   s)    FJ05(
+
G Gr,   rH   c                       \ rS rSrS rS rS rS r\S 5       r	S r
\" 5       S 5       r  SS jrS rS rSS jr\" S
S9S 5       rS rS rS rSrg	)
ClassMixin   c                     gNT r$   s    r*   is_classClassMixin.is_class       r,   c                     grm   rn   ro   s    r*   is_class_mixinClassMixin.is_class_mixin   rr   r,   c                     SSK Jn  SSKJn  U R	                  5       (       a  [        U" U 5      /5      $ [        U" U R                  U R                  X5      /5      $ )Nr   )TreeInstance)	TypedDict)jedi.inference.valuerw   jedi.inference.gradual.typingrx   is_typeddictr   r2   r1   )r$   	argumentsrw   rx   s       r*   
py__call__ClassMixin.py__call__   sM    5;Yt_-..d&:&:D<O<OQUabccr,   c                 D    [         R                  " U R                  S5      $ )Ntype)r
   builtin_from_namer2   ro   s    r*   py__class__ClassMixin.py__class__   s    ))$*>*>GGr,   c                 @    [        X R                  R                  5      $ r   )r   	tree_noderU   ro   s    r*   rU   ClassMixin.name   s    ~~2233r,   c                 .    U R                   R                  $ r   )rU   string_namero   s    r*   
py__name__ClassMixin.py__name__   s    yy$$$r,   c              #   6  #    U /nU v   U R                  5        HQ  nUR                  5        H:  n UR                  nU" 5        H  nXQ;  d  M
  UR                  U5        Uv   M!     M<     MS     g ! [         a     [
        R                  " SX5         Mh  f = f7f)Nz$Super class of %s is not a class: %s)py__bases__r6   	py__mro__appendAttributeErrorr   warning)r$   mrolazy_clscls
mro_methodcls_news         r*   r   ClassMixin.py__mro__   s     f
 ((*H  ~~'*!$J $.<"-JJw/")M $0' ( + & U	 MM"H$TUs-   .BA0B"B0"BBBBNFc              #     #    U(       a0  U R                  5       nU(       a  U R                  XR5       S h  vN   U R                  5        HL  nUR                  5       (       a  UR	                  US9 S h  vN   M1  [        XR                  5       UUS9v   MN     U(       d  U(       a  SSKJn  U" U R                  S5      n[        U[        5      (       d   eX:w  aa  [        / 5      n	UR                  U	5       H@  n
U
R	                  5       n[        US 5        [        US 5        [        US 5      nUc   eUv   MB     g g g g  GN N7f)N)rP   )rO   rL   rP   r   )r   r   )get_metaclassesget_metaclass_filtersr   is_compiledget_filtersrH   rM   jedi.inference.compiledr   r2   
isinstance
ClassValuer   r}   next)r$   rL   rP   include_metaclassesinclude_type_when_classmetaclassesr   r   r=   argsr/   instance_filtersxs                r*   r   ClassMixin.get_filters   s+    ..0K55kOOO>>#C  ??{?CCC!~~'7!- + 	 $ 6A%d&:&:FCEeZ0000} 'r* % 0 0 6H'/';';'=$)40)40-t4A=(=G !7 	  7{ P Ds"   3EE>E4E5CEEc                 "   U R                  5       nU(       a  U R                  U5      nU(       a  U$ [        / 5      nU R                  U5      R	                  S5      nUR                  5        Vs/ s H  oUR                  U 5      PM     sn$ s  snf )Nr!   )r   get_metaclass_signaturesr   r}   py__getattribute__get_signaturesbind)r$   r   sigsr   
init_funcssigs         r*   r   ClassMixin.get_signatures   sy     **,00=Dr"__T*==jI
*4*C*C*EF*E3*EFFFs   /Bc                     [        U 5      $ r   r   ro   s    r*   _as_contextClassMixin._as_context   s    D!!r,   c                 V    U(       a  SU R                  5       -  $ U R                  5       $ )NzType[%s])r   )r$   add_class_infos     r*   get_type_hintClassMixin.get_type_hint   s$     111  r,   defaultc                 X   SSK Jn  U R                  5        H~  n[        U[        5      (       d    gUR
                  n[        U5      (       d    gUR                  5        H2  n[        XA5      (       a      g UR                  nU" 5       (       a      gM4     M     g! [         a         gf = f)Nr   )TypedDictClassFT)
rz   r   r   r   r   datar   r6   r{   r   )r$   r   r   r   r   methods         r*   r{   ClassMixin.is_typeddict   s     	A((*Hh66 I "),,~~'c22	$ --F xx#   ( +.  & ! !	!s   6B
B)(B)c                    ^ ^^ SSK Jm  U(       d"  [        R                  " S5        [	        T /5      $ [	        UUU 4S jU 5       5      $ )Nr   GenericClassz:Class indexes inferred to nothing. Returning class insteadc           	   3   Z   >#    U  H   nT" T[        TR                  US 95      v   M"     g7f))context_of_indexindex_valueN)r   context).0r   r   contextualized_noder$   s     r*   	<genexpr>+ClassMixin.py__getitem__.<locals>.<genexpr>  s=      	
  / "%8%@%@ +   /s   (+)jedi.inference.gradual.baser   r   r   r   )r$   index_value_setr   r   s   ` `@r*   py__getitem__ClassMixin.py__getitem__  s?    <MMVWTF## 	
  /	
 	
 		
r,   c                 2    SSK Jn  U" U [        U5      5      $ )Nr   r   )r   r   r   )r$   generics_tupler   s      r*   with_genericsClassMixin.with_generics#  s    </
 	
r,   c                    ^ ^ SSK Jn  U U4S jnT(       a*  [        U" T [        [	        U" 5       5      5      5      /5      $ [        T 15      $ )Nr   r   c               3      >#    TR                  5        H)  n TR                  U R                  5       [        5      v   M+     g7f)a  
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_vars3ClassMixin.define_generics.<locals>.remap_type_vars-  s7      !//1#''(;(;(=yII 2s   ?A)r   r   r   r   tuple)r$   r   r   r   s   ``  r*   define_genericsClassMixin.define_generics*  sL    <	J \#E/*;$<=    r,   rn   )NFTT)T)r@   rA   rB   rC   rp   rt   r}   r   r:   rU   r   r	   r   r   r   r   r   r   r{   r   r   r   rD   rn   r,   r*   rj   rj      s    dH 4 4% ,-* .*@ :?FJ DG"!
 "%0 1:
 
 r,   rj   c                       \ rS rSrSr\" 5       S 5       rS r\" SS9S 5       r\	R                  " 5       S 5       r\" \S9S	 5       r\	R                  " 5       S
 5       rSrg)r   iB  classc                     / nU R                   R                  5       nUc  / $ [        U5       HF  u  p4U(       a  M  SSKJn  U" U R
                  U5       H  nXa;  d  M
  UR                  U5        M     MH     U$ )Nr   )find_unknown_type_vars)r   get_super_arglistr   !jedi.inference.gradual.annotationr   r1   r   )r$   foundargliststarsr\   r   r   s          r*   r   ClassValue.list_type_varsE  sn    ..224?I)'2KEP243F3FM(LL* N 3 r,   c                     U R                   R                  5       nU(       a-  SSKJn  UR	                  U R
                  U R                  U5      $ g )Nr   )r|   )r   r   jedi.inferencer|   TreeArgumentsr2   r1   )r$   r   r|   s      r*   _get_bases_argumentsClassValue._get_bases_argumentsW  s?    ..2240**4+?+?ATATV]^^r,   rn   r   c                 `   U R                  5       nUb2  UR                  5        VVs/ s H  u  p#Ub  M
  UPM     nnnU(       a  U$ U R                  5       S:X  a!  U R                  R	                  5       (       a  / $ [        U R                  R                  R                  S5      5      /$ s  snnf )Nobject)	r   unpackr   r1   is_builtins_moduler   r2   builtins_moduler   )r$   r   keyra   lsts        r*   r   ClassValue.py__bases__^  s    ((*+/;;=H=ZSC5=CH
??(''::<<I  00CCHM
  	 Is
   	B*B*c                 4    [         R                  " SU5        / $ )NzUnprocessed metaclass %s)r   r   )r$   r   rP   s      r*   r    ClassValue.get_metaclass_filtersm  s    0+>	r,   c                    U R                  5       nUbd  UR                  5        VVs/ s H  u  p#US:X  d  M  UPM     nnn[        R                  " S U 5       5      n[        S U 5       5      nU(       a  U$ U R	                  5        HN  nUR                  5        H7  nUR                  5       (       d  M  UR                  5       nU(       d  M3  Us  s  $    MP     [        $ s  snnf )N	metaclassc              3   @   #    U  H  oR                  5       v   M     g 7fr   )r6   )r   
lazy_values     r*   r   -ClassValue.get_metaclasses.<locals>.<genexpr>w  s     ,TRSJ-=-=-?-?RSs   c              3   R   #    U  H  oR                  5       (       d  M  Uv   M     g 7fr   )rp   )r   ms     r*   r   r   x  s     "JkZZ\11ks   '	')	r   r   r   	from_setsr   r6   rp   r   r   )r$   r   r   ra   r   r   	lazy_basevaluess           r*   r   ClassValue.get_metaclassesr  s    ((*)-M:3#:LAM",,,TRS,TTK""Jk"JJK""))+I"*>>##"224Fv%	 + ,  Ns
   C C c                     / $ r   rn   )r$   r   s     r*   r   #ClassValue.get_metaclass_signatures  s    	r,   N)r@   rA   rB   rC   r;   r   r   r   r   r   decorater   r   r   r   rD   rn   r,   r*   r   r   B  s    H!# $" ""- .   ")4 5"  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   rH   rj   r   rn   r,   r*   <module>r     s   %L  + + # D 3 > D  / > S '!" !H$G" $GN{  { |D1_ Dr,   