a
    lc-A                     @   s  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 deZ%G dd deZ&G dd dZ'G dd de'ee	d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                       s8   e Zd Z fddZedd Ze fddZ  ZS )	ClassNamec                    s   t  || || _|| _d S N)super__init___apply_decorators_class_value)selfclass_value	tree_namename_contextapply_decorators	__class__ V/var/www/html/django/DPS/env/lib/python3.9/site-packages/jedi/inference/value/klass.pyr   :   s    zClassName.__init__c                 c   sR   ddl m} || jj| j| j}|D ](}| jrF|jd | jdE d H  q$|V  q$d S )Nr   )tree_name_to_values)instancer!   )Zjedi.inference.syntax_treer)   parent_contextinference_stater"   r   Z	py__get__r   )r    r)   inferredZresult_valuer'   r'   r(   infer?   s    zClassName.inferc                    s*   t  j}|dkr&| j }t|r&dS |S )Nfunctionproperty)r   api_typer"   get_definitionr   )r    type_Z
definitionr%   r'   r(   r1   L   s    
zClassName.api_type)	__name__
__module____qualname__r   r   r.   r0   r1   __classcell__r'   r'   r%   r(   r   9   s
   
r   c                       sB   e Zd Zd fdd	Zdd Zdd Zd	d
 Z fddZ  ZS )ClassFilterNFc                    s(   t  j| |||d || _|| _d S )N)until_positionorigin_scope)r   r   
as_contextr   _is_instance)r    r!   node_contextr9   r:   is_instancer%   r'   r(   r   \   s    zClassFilter.__init__c                    s    fdd|D S )Nc                    s$   g | ]}t  j| j j d qS ))r!   r"   r#   r$   )r   r   Z_node_contextr<   .0namer    r'   r(   
<listcomp>g   s   z.ClassFilter._convert_names.<locals>.<listcomp>r'   r    namesr'   rB   r(   _convert_namesf   s    
zClassFilter._convert_namesc                 C   s8   | j }|d ur4|| jks"|| jkr&dS t| j|}qdS )NTF)Z_origin_scopeZ_parser_scoper+   r   Z_parso_cache_node)r    noder'   r'   r(   _equals_origin_scopep   s    z ClassFilter._equals_origin_scopec                 C   sv   | j sT| }|d urT|jdkrT|jd }|jdkrTd|jd  vrTd|jvrTdS |jd pt|jdpt|  S )N	expr_stmt   	annassignClassVar=F__)	r<   r2   typechildrenget_codevalue
startswithendswithrH   )r    rA   rI   rK   r'   r'   r(   _access_possiblex   s    

zClassFilter._access_possiblec                    s   t  |} fdd|D S )Nc                    s   g | ]}  |r|qS r'   )rU   r?   rB   r'   r(   rC          z'ClassFilter._filter.<locals>.<listcomp>)r   _filterrD   r%   rB   r(   rW      s    zClassFilter._filter)NNNF)	r4   r5   r6   r   rF   rH   rU   rW   r7   r'   r'   r%   r(   r8   [   s     

r8   c                   @   s   e Zd Zdd Zdd Zdd Zdd Zed	d
 Zdd Z	e
 dd Zd#ddZdd Zdd Zd$ddZedddd Zdd Zdd  Zd!d" ZdS )%
ClassMixinc                 C   s   dS NTr'   rB   r'   r'   r(   is_class   s    zClassMixin.is_classc                 C   s   dS rY   r'   rB   r'   r'   r(   is_class_mixin   s    zClassMixin.is_class_mixinc                 C   sF   ddl m} ddlm} |  r.t|| gS t|| j| j| |gS )Nr   )TreeInstance)	TypedDict)Zjedi.inference.valuer\   jedi.inference.gradual.typingr]   is_typeddictr   r,   r+   )r    	argumentsr\   r]   r'   r'   r(   
py__call__   s
    zClassMixin.py__call__c                 C   s   t | jdS )NrO   )r	   builtin_from_namer,   rB   r'   r'   r(   py__class__   s    zClassMixin.py__class__c                 C   s   t | | jjS r   )r   	tree_noderA   rB   r'   r'   r(   rA      s    zClassMixin.namec                 C   s   | j jS r   )rA   Zstring_namerB   r'   r'   r(   
py__name__   s    zClassMixin.py__name__c              
   c   s|   | g}| V  |   D ]b}| D ]T}z
|j}W n  tyN   td| | Y q 0 | D ]}||vrV|| |V  qVq qd S )Nz$Super class of %s is not a class: %s)py__bases__r.   	py__mro__AttributeErrorr   warningappend)r    mrolazy_clsclsZ
mro_methodZcls_newr'   r'   r(   rg      s    


zClassMixin.py__mro__NFTc                 c   s   |r"|   }|r"| ||E d H  |  D ]6}| rJ|j|dE d H  q*t| | ||dV  q*|s|rddlm} || j	d}t
|tsJ || krtg }	||	D ]<}
|
 }t|d  t|d  t|d }|d usJ |V  qd S )N)r>   )r=   r:   r>   r   )rb   rO   )get_metaclassesget_metaclass_filtersrg   Zis_compiledget_filtersr8   r;   Zjedi.inference.compiledrb   r,   
isinstance
ClassValuer   ra   next)r    r:   r>   Zinclude_metaclassesZinclude_type_when_classmetaclassesrm   rb   r3   argsr*   Zinstance_filtersxr'   r'   r(   rp      s2    



zClassMixin.get_filtersc                    sL      }|r |}|r|S tg } |d} fdd| D S )Nr   c                    s   g | ]}|  qS r'   )bind)r@   sigrB   r'   r(   rC      rV   z-ClassMixin.get_signatures.<locals>.<listcomp>)rn   get_metaclass_signaturesr   ra   py__getattribute__get_signatures)r    rt   Zsigsru   Z
init_funcsr'   rB   r(   r{      s    
zClassMixin.get_signaturesc                 C   s   t | S r   r   rB   r'   r'   r(   _as_context   s    zClassMixin._as_contextc                 C   s   |rd|    S |   S )NzType[%s])re   )r    Zadd_class_infor'   r'   r(   get_type_hint   s    zClassMixin.get_type_hintdefaultc              
   C   s   ddl m} |  D ]z}t|ts( dS |j}t|s< dS | D ]H}t||rZ  dS z
|j}W n t	y|   Y   dS 0 | rD  dS qDqdS )Nr   )TypedDictClassFT)
r^   r   rf   rq   r   datar   r.   r_   rh   )r    r   rl   rd   rm   methodr'   r'   r(   r_     s"    


zClassMixin.is_typeddictc                    s>   ddl m  |s$td tgS t fdd|D S )Nr   GenericClassz:Class indexes inferred to nothing. Returning class insteadc                 3   s"   | ]} t j|d V  qdS ))Zcontext_of_indexindex_valueN)r   context)r@   r   r   contextualized_noder    r'   r(   	<genexpr>%  s   z+ClassMixin.py__getitem__.<locals>.<genexpr>)jedi.inference.gradual.baser   r   ri   r   )r    Zindex_value_setr   r'   r   r(   py__getitem__   s    

zClassMixin.py__getitem__c                 C   s   ddl m} || t|S )Nr   r   )r   r   r   )r    Zgenerics_tupler   r'   r'   r(   with_generics0  s
    zClassMixin.with_genericsc                    sB   ddl m}  fdd}r8t| tt| gS t hS )Nr   r   c                  3   s$      D ]} |  tV  qd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getre   r   )type_varr    type_var_dictr'   r(   remap_type_vars:  s    
z3ClassMixin.define_generics.<locals>.remap_type_vars)r   r   r   r   tuple)r    r   r   r   r'   r   r(   define_generics7  s    zClassMixin.define_generics)NFTT)T)r4   r5   r6   rZ   r[   ra   rc   r0   rA   re   r   rg   rp   r{   r|   r}   r   r_   r   r   r   r'   r'   r'   r(   rX      s(   

   
"

rX   c                   @   sj   e Zd ZdZe dd Zdd Zedddd	 Ze	 d
d Z
eeddd Ze	 dd ZdS )rr   classc                 C   sf   g }| j  }|d u rg S t|D ]>\}}|r0q"ddlm} || j|D ]}||vrH|| qHq"|S )Nr   )find_unknown_type_vars)rd   get_super_arglistr   Z!jedi.inference.gradual.annotationr   r+   rj   )r    foundargliststarsrG   r   r   r'   r'   r(   r   R  s    
zClassValue.list_type_varsc                 C   s0   | j  }|r,ddlm} || j| j|S d S )Nr   )r`   )rd   r   jedi.inferencer`   ZTreeArgumentsr,   r+   )r    r   r`   r'   r'   r(   _get_bases_argumentsd  s
    
zClassValue._get_bases_argumentsr'   r~   c                 C   sX   |   }|d ur*dd | D }|r*|S |  dkrD| j rDg S t| jjdgS )Nc                 S   s   g | ]\}}|d u r|qS r   r'   r@   keyrR   r'   r'   r(   rC   o  rV   z*ClassValue.py__bases__.<locals>.<listcomp>object)	r   unpackre   r+   Zis_builtins_moduler
   r,   Zbuiltins_modulerz   )r    ru   lstr'   r'   r(   rf   k  s    zClassValue.py__bases__c                 C   s   t d| g S )NzUnprocessed metaclass %s)r   ri   )r    rt   r>   r'   r'   r(   ro   z  s    z ClassValue.get_metaclass_filtersc                 C   s   |   }|d urPdd | D }tdd |D }tdd |D }|rP|S |  D ]2}| D ]$}| rd| }|rd|    S qdqXtS )Nc                 S   s   g | ]\}}|d kr|qS 	metaclassr'   r   r'   r'   r(   rC     rV   z.ClassValue.get_metaclasses.<locals>.<listcomp>c                 s   s   | ]}|  V  qd S r   )r.   )r@   Z
lazy_valuer'   r'   r(   r     rV   z-ClassValue.get_metaclasses.<locals>.<genexpr>c                 s   s   | ]}|  r|V  qd S r   )rZ   )r@   mr'   r'   r(   r     rV   )	r   r   r   Z	from_setsrf   r.   rZ   rn   r   )r    ru   r   rt   Z	lazy_baserR   valuesr'   r'   r(   rn     s    zClassValue.get_metaclassesc                 C   s   g S r   r'   )r    rt   r'   r'   r(   ry     s    z#ClassValue.get_metaclass_signaturesN)r4   r5   r6   r1   r   r   r   rf   r   Zdecoratero   r   rn   ry   r'   r'   r'   r(   rr   O  s   



rr   r   N))__doc__Zjedir   Zjedi.parser_utilsr   r   r   Zjedi.inference.cacher   r   r   r   r	   Zjedi.inference.lazy_valuer
   r   Zjedi.inference.filtersr   Zjedi.inference.namesr   r   Zjedi.inference.argumentsr   r   Zjedi.inference.base_valuer   r   r   Zjedi.inference.contextr   Zjedi.inference.value.functionr   Zjedi.inference.gradual.genericsr   r   Zjedi.pluginsr   r   r8   rX   rr   r'   r'   r'   r(   <module>   s$   &"6 ?