
    fD>                     (   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(y)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                   B     e Zd Z fdZed        Ze fd       Z xZS )	ClassNamec                 B    t         |   ||       || _        || _        y N)super__init___apply_decorators_class_value)selfclass_value	tree_namename_contextapply_decorators	__class__s        U/var/www/cvtools/html/venv/lib/python3.12/site-packages/jedi/inference/value/klass.pyr    zClassName.__init__:   s"    y1!1'    c              #      K   ddl m}  || j                  j                  | j                  | j                        }|D ]8  }| j
                  r&|j                  d | j                        E d {    5| : y 7 w)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?   sv      	C&//1D1DdnnV % 	#L%%'114TM^M^1___""		#_s   A*A;,A9-A;c                 z    t         |   }|dk(  r*| j                  j                         }||S t	        |      ry|S )Nfunctionproperty)r   api_typer%   get_definitionr   )r#   type_
definitionr(   s      r)   r8   zClassName.api_typeL   sD     J668J!#J/ "r*   )	__name__
__module____qualname__r    r   r4   r7   r8   __classcell__r(   s   @r)   r   r   9   s0    (
 
# 
#  r*   r   c                   @     e Zd Z	 	 d fd	Zd Zd Zd Z fdZ xZS )ClassFilterc                 d    t         |   |j                         |||       || _        || _        y )N)until_positionorigin_scope)r   r    
as_contextr"   _is_instance)r#   r$   node_contextrD   rE   is_instancer(   s         r)   r    zClassFilter.__init__^   s;    ""$l)% 	 	

 ('r*   c           	          |D cg c]0  }t        | j                  || j                  | j                         2 c}S c c}w )N)r$   r%   r&   r'   )r   r"   _node_contextrG   )r#   namesnames      r)   _convert_nameszClassFilter._convert_namesh   sL      
   --!//%)%6%6!6	
 	
 
s   5=c                     | j                   }|8|| j                  k(  s|| j                  k(  ryt        | j                  |      }|8y)NTF)_origin_scope_parser_scoper/   r   _parso_cache_node)r#   nodes     r)   _equals_origin_scopez ClassFilter._equals_origin_scoper   sP    !!t)))TT5H5H-H*4+A+A4HD  r*   c                     |j                   j                  d       xs- |j                   j                  d      xs | j                         S )N__)value
startswithendswithrT   )r#   rM   s     r)   _access_possiblezClassFilter._access_possiblez   sC    ::((.. +$**2E2Ed2K +((*	+r*   c                 p    t         |   |      }|D cg c]  }| j                  |      s| c}S c c}w r   )r   _filterrZ   )r#   rL   rM   r(   s      r)   r\   zClassFilter._filter   s2    &!&F$*?*?*EFFFs   33)NNNF)	r<   r=   r>   r    rN   rT   rZ   r\   r?   r@   s   @r)   rB   rB   ]   s)    FJ05(
+
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y)
ClassMixinc                      yNT r#   s    r)   is_classzClassMixin.is_class       r*   c                      yr`   ra   rb   s    r)   is_class_mixinzClassMixin.is_class_mixin   rd   r*   c                     ddl m} ddlm} | j	                         rt         ||       g      S t         || j                  | j                  | |      g      S )Nr   )TreeInstance)	TypedDict)jedi.inference.valuerh   jedi.inference.gradual.typingri   is_typeddictr   r0   r/   )r#   	argumentsrh   ri   s       r)   
py__call__zClassMixin.py__call__   sM    5;Yt_-..d&:&:D<O<OQUW`abccr*   c                 B    t        j                  | j                  d      S )Ntype)r
   builtin_from_namer0   rb   s    r)   py__class__zClassMixin.py__class__   s    ))$*>*>GGr*   c                 B    t        | | j                  j                        S r   )r   	tree_noderM   rb   s    r)   rM   zClassMixin.name   s    t~~2233r*   c                 .    | j                   j                  S r   )rM   string_namerb   s    r)   
py__name__zClassMixin.py__name__   s    yy$$$r*   c              #   "  K   | g}|  | j                         D ]J  }|j                         D ]5  }	 |j                  } |       D ]  }||vs|j                  |       |  7 L y # t        $ r 	 t        j                  d| |       Y ^w xY ww)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)   rz   zClassMixin.py__mro__   s     f
 ((* 	*H  ~~' **!$J $.< *"#-JJw/")M*'*	* & U	 MM"H$PSTUs-   .BA(BB(!B	BBBNFc              #   V  K   |r,| j                         }|r| j                  ||      E d {    | j                         D ]L  }|j                         r|j	                  |      E d {    .t        | |j                         ||       N |s|rddlm}  || j                  d      }t        |t              sJ || k7  r^t        g       }	|j                  |	      D ]>  }
|
j	                         }t        |d        t        |d        t        |d       }|J | @ y y y y 7 7 w)N)rI   )rH   rE   rI   r   )rq   rp   )get_metaclassesget_metaclass_filtersrz   is_compiledget_filtersrB   rF   jedi.inference.compiledrq   r0   
isinstance
ClassValuer   rn   next)r#   rE   rI   include_metaclassesinclude_type_when_classmetaclassesr   rq   r:   argsr-   instance_filtersxs                r)   r   zClassMixin.get_filters   s7    ..0K55k;OOO>># 	C ??{?CCC!s~~'7!- + 		 6A%d&:&:FCEeZ000} 'r* % 0 0 6 H'/';';'=$)40)40-t4A=(=G 	  7{ P Ds"   *D)D%<D))D'*B<D)'D)c                 
   | j                         }|r| j                  |      }|r|S t        g       }| j                  |      j	                  d      }|j                         D cg c]  }|j                  |        c}S c c}w )Nr    )r   get_metaclass_signaturesr   rn   py__getattribute__get_signaturesbind)r#   r   sigsr   
init_funcssigs         r)   r   zClassMixin.get_signatures   su     **,00=Dr"__T*==jI
*4*C*C*EF3FFFs   %B c                     t        |       S r   r   rb   s    r)   _as_contextzClassMixin._as_context   s    D!!r*   c                 L    |rd| j                         z  S | j                         S )NzType[%s])rw   )r#   add_class_infos     r)   get_type_hintzClassMixin.get_type_hint   s$     111  r*   defaultc                 (   ddl m} | j                         D ]h  }t        |t              s y|j
                  }t        |      s y|j                         D ](  }t        ||      r  y	 |j                  } |       s'  y j y# t        $ r Y   yw xY w)Nr   )TypedDictClassFT)
rk   r   ry   r   r   datar   r4   rl   r|   )r#   r   r   rt   r   methods         r)   rl   zClassMixin.is_typeddict   s     	A((* 	$Hh6 I "),~~' $c>2	$ --F x#$	$.  & ! !	!s   (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   Z   K   | ]"  } t        j                  |              $ yw))context_of_indexindex_valueN)r   context).0r   r   contextualized_noder#   s     r)   	<genexpr>z+ClassMixin.py__getitem__.<locals>.<genexpr>  s7      	
  "%8%@%@ +	
s   (+)jedi.inference.gradual.baser   r   r}   r   )r#   index_value_setr   r   s   ` `@r)   py__getitem__zClassMixin.py__getitem__  s?    <MMVWTF## 	
  /	
 	
 		
r*   c                 2    ddl m}  || t        |            S )Nr   r   )r   r   r   )r#   generics_tupler   s      r)   with_genericszClassMixin.with_generics#  s    </
 	
r*   c                      ddl m}  fd}r*t         | t        t	         |                         g      S t         h      S )Nr   r   c               3      K   j                         D ](  } j                  | j                         t               * yw)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getrw   r   )type_varr#   type_var_dicts    r)   remap_type_varsz3ClassMixin.define_generics.<locals>.remap_type_vars-  s?      !//1 J#''(;(;(=yIIJs   =A )r   r   r   r   tuple)r#   r   r   r   s   ``  r)   define_genericszClassMixin.define_generics*  sL    <	J \#E/*;$<=    r*   )NFTT)T)r<   r=   r>   rc   rf   rn   rr   r7   rM   rw   r	   rz   r   r   r   r   r   rl   r   r   r   ra   r*   r)   r^   r^      s    dH 4 4% ,-* .*@ :?FJ DG"!
 "%0 1:
 
 r*   r^   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y
)r   classc                     g }| j                   j                         }|g S t        |      D ]<  \  }}|r	ddlm}  || j
                  |      D ]  }||vs|j                  |        > |S )Nr   )find_unknown_type_vars)rt   get_super_arglistr   !jedi.inference.gradual.annotationr   r/   r{   )r#   foundargliststarsrS   r   r   s          r)   r   zClassValue.list_type_varsE  s{    ..224?I)'2 	+KE4P243F3FM +5(LL*+	+ r*   c                     | j                   j                         }|r-ddlm} |j	                  | j
                  | j                  |      S y )Nr   )rm   )rt   r   jedi.inferencerm   TreeArgumentsr0   r/   )r#   r   rm   s      r)   _get_bases_argumentszClassValue._get_bases_argumentsW  s?    ..2240**4+?+?ATATV]^^r*   ra   r   c                 @   | j                         }|)|j                         D cg c]
  \  }}|	| }}}|r|S | j                         dk(  r| j                  j	                         rg S t        | j                  j                  j                  d            gS c c}}w )Nobject)	r   unpackrw   r/   is_builtins_moduler   r0   builtins_moduler   )r#   r   keyrW   lsts        r)   ry   zClassValue.py__bases__^  s    ((*+/;;=HZS%CK5HCH
??(''::<I  00CCHM
  	 Is
   
BBc                 2    t        j                  d|       g S )NzUnprocessed metaclass %s)r   r}   )r#   r   rI   s      r)   r   z ClassValue.get_metaclass_filtersm  s    0+>	r*   c                    | j                         }|Z|j                         D cg c]  \  }}|dk(  s| }}}t        j                  d |D              }t        d |D              }|r|S | j	                         D ]@  }|j                         D ]+  }|j                         s|j                         }|s'|c c S  B t        S c c}}w )N	metaclassc              3   <   K   | ]  }|j                           y wr   )r4   )r   
lazy_values     r)   r   z-ClassValue.get_metaclasses.<locals>.<genexpr>w  s     ,TJZ-=-=-?,Ts   c              3   B   K   | ]  }|j                         s|  y wr   )rc   )r   ms     r)   r   z-ClassValue.get_metaclasses.<locals>.<genexpr>x  s     "JQZZ\1"Js   )	r   r   r   	from_setsry   r4   rc   r   r   )r#   r   r   rW   r   r   	lazy_basevaluess           r)   r   zClassValue.get_metaclassesr  s    ((*)-M:3#:LMAM",,,TRS,TTK""Jk"JJK""))+ 	&I"* &>>#"224F%	&	&  Ns
   CCc                     g S r   ra   )r#   r   s     r)   r   z#ClassValue.get_metaclass_signatures  s    	r*   N)r<   r=   r>   r8   r   r   r   ry   r   decorater   r   r   r   ra   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   rB   r^   r   ra   r*   r)   <module>r      s   %L  + + # D 3 > D  / > S '!" !H$G" $GN{  { |D1_ Dr*   