o
    ð›hD>  ã                   @   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__© úPc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/value/klass.pyr   :   s   
zClassName.__init__c                 c   sT   � ddl m} || jj| j| jƒ}|D ]}| jr$|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                    s6   t ƒ j}|dkr| j ¡ }|d u r|S t|ƒrdS |S )NÚfunctionÚproperty)r   Úapi_typer"   Z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                       sF   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_contextr8   r9   Ú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>i   s    ûüÿz.ClassFilter._convert_names.<locals>.<listcomp>r'   ©r    Únamesr'   rA   r(   Ú_convert_namesh   s   
úzClassFilter._convert_namesc                 C   s>   | j }|d ur|| jks|| jkrdS t| j|ƒ}|d usdS )NTF)Z_origin_scopeZ_parser_scoper+   r   Z_parso_cache_node)r    Únoder'   r'   r(   Ú_equals_origin_scoper   s   ýz ClassFilter._equals_origin_scopec                 C   s"   |j  d¡ p|j  d¡p|  ¡ S )NÚ__)ÚvalueÚ
startswithÚendswithrG   )r    r@   r'   r'   r(   Ú_access_possiblez   s   ÿzClassFilter._access_possiblec                    s   t ƒ  |¡}‡ fdd„|D ƒS )Nc                    s   g | ]	}ˆ   |¡r|‘qS r'   )rL   r>   rA   r'   r(   rB   �   s    z'ClassFilter._filter.<locals>.<listcomp>)r   Ú_filterrC   r%   rA   r(   rM      s   zClassFilter._filter)NNNF)	r3   r4   r5   r   rE   rG   rL   rM   r6   r'   r'   r%   r(   r7   ]   s    ÿ

r7   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   ó   dS ©NTr'   rA   r'   r'   r(   Úis_class…   ó   zClassMixin.is_classc                 C   rO   rP   r'   rA   r'   r'   r(   Úis_class_mixinˆ   rR   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.valuerT   Újedi.inference.gradual.typingrU   Úis_typeddictr   r,   r+   )r    Ú	argumentsrT   rU   r'   r'   r(   Ú
py__call__‹   s
   zClassMixin.py__call__c                 C   s   t  | jd¡S )NÚtype)r	   Úbuiltin_from_namer,   rA   r'   r'   r(   Úpy__class__“   s   zClassMixin.py__class__c                 C   s   t | | jjƒS r   )r   Ú	tree_noder@   rA   r'   r'   r(   r@   –   s   zClassMixin.namec                 C   s   | j jS r   )r@   Zstring_namerA   r'   r'   r(   Ú
py__name__š   ó   zClassMixin.py__name__c              
   c   s€   � | g}| V  |   ¡ D ]2}| ¡ D ]+}z|j}W n ty)   	 t d| |¡ Y qw |ƒ D ]}||vr;| |¡ |V  q-q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(   ra   �   s&   €

ô

€ýíýzClassMixin.py__mro__NFTc                 c   sú   � |r|   ¡ }|r|  ||¡E d H  |  ¡ D ]}| ¡ r&|j|d�E d H  qt| | ¡ ||d�V  q|su|rwddlm} || j	dƒ}t
|tƒsIJ ‚|| krytg ƒ}	| |	¡D ]$}
|
 ¡ }t|d ƒ t|d ƒ t|d ƒ}|d usqJ ‚|V  qVd S d S d S d S )N)r=   )r<   r9   r=   r   )r[   rZ   )Úget_metaclassesÚget_metaclass_filtersra   Zis_compiledÚget_filtersr7   r:   Zjedi.inference.compiledr[   r,   Ú
isinstanceÚ
ClassValuer   rY   Únext)r    r9   r=   Zinclude_metaclassesZinclude_type_when_classÚmetaclassesrg   r[   r2   Úargsr*   Zinstance_filtersÚxr'   r'   r(   rj   ¾   s:   €
ý


ð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?   ÚsigrA   r'   r(   rB   ë   s    z-ClassMixin.get_signatures.<locals>.<listcomp>)rh   Úget_metaclass_signaturesr   rY   Úpy__getattribute__Úget_signatures)r    rn   Zsigsro   Z
init_funcsr'   rA   r(   ru   à   s   
zClassMixin.get_signaturesc                 C   s   t | ƒS r   r   rA   r'   r'   r(   Ú_as_contextí   r_   zClassMixin._as_contextc                 C   s   |rd|   ¡  S |   ¡ S )NzType[%s])r^   )r    Zadd_class_infor'   r'   r(   Úget_type_hintð   s   zClassMixin.get_type_hint©Údefaultc              
   C   s”   ddl m} |  ¡ D ]=}t|tƒs dS |j}t|ƒs dS | ¡ D ]$}t||ƒr-  dS z|j}W n t	y>   Y   dS w |ƒ rF  dS q"q
dS )Nr   )ÚTypedDictClassFT)
rV   rz   r`   rk   r   Údatar   r.   rW   rb   )r    rz   rf   r]   rg   Úmethodr'   r'   r(   rW   õ   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   rc   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_generics#  s
   þzClassMixin.with_genericsc                    sB   ddl m} ‡ ‡fdd„}ˆrt|ˆ 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Úgetr^   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_generics*  s   þ
zClassMixin.define_generics)NFTT)T)r3   r4   r5   rQ   rS   rY   r\   r0   r@   r^   r   ra   rj   ru   rv   rw   r   rW   r…   r†   rŽ   r'   r'   r'   r(   rN   „   s*    

 
ÿ"

rN   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 )rl   Úclassc                 C   sf   g }| j  ¡ }|d u rg S t|ƒD ]\}}|rqddlm} || j|ƒD ]}||vr/| |¡ q$q|S )Nr   )Úfind_unknown_type_vars)r]   Úget_super_arglistr   Z!jedi.inference.gradual.annotationr�   r+   rd   )r    ÚfoundÚarglistÚstarsrF   r�   r‰   r'   r'   r(   r‡   E  s   

€ýzClassValue.list_type_varsc                 C   s0   | j  ¡ }|rddlm} | | j| j|¡S d S )Nr   )rX   )r]   r‘   Újedi.inferencerX   ZTreeArgumentsr,   r+   )r    r“   rX   r'   r'   r(   Ú_get_bases_argumentsW  s
   
zClassValue._get_bases_argumentsr'   rx   c                 C   sX   |   ¡ }|d urdd„ | ¡ D ƒ}|r|S |  ¡ dkr"| j ¡ r"g S t| jj d¡ƒgS )Nc                 S   s   g | ]
\}}|d u r|‘qS r   r'   ©r?   ÚkeyrI   r'   r'   r(   rB   b  ó    z*ClassValue.py__bases__.<locals>.<listcomp>Úobject)	r–   Úunpackr^   r+   Zis_builtins_moduler
   r,   Zbuiltins_modulert   )r    ro   Úlstr'   r'   r(   r`   ^  s   ÿÿzClassValue.py__bases__c                 C   s   t  d|¡ g S )NzUnprocessed metaclass %s)r   rc   )r    rn   r=   r'   r'   r(   ri   m  s   z ClassValue.get_metaclass_filtersc                 C   s�   |   ¡ }|d ur(dd„ | ¡ D ƒ}t dd„ |D ƒ¡}tdd„ |D ƒƒ}|r(|S |  ¡ D ]}| ¡ D ]}| ¡ rD| ¡ }|rD|    S q2q,tS )Nc                 S   s   g | ]
\}}|d kr|‘qS ©Ú	metaclassr'   r—   r'   r'   r(   rB   v  r™   z.ClassValue.get_metaclasses.<locals>.<listcomp>c                 s   s   � | ]}|  ¡ V  qd S r   )r.   )r?   Z
lazy_valuer'   r'   r(   rƒ   w  s   € z-ClassValue.get_metaclasses.<locals>.<genexpr>c                 s   s   � | ]	}|  ¡ r|V  qd S r   )rQ   )r?   Úmr'   r'   r(   rƒ   x  s   € )	r–   r›   r   Z	from_setsr`   r.   rQ   rh   r   )r    ro   rŸ   rn   Z	lazy_baserI   Úvaluesr'   r'   r(   rh   r  s    €üzClassValue.get_metaclassesc                 C   s   g S r   r'   )r    rn   r'   r'   r(   rs   „  s   z#ClassValue.get_metaclass_signaturesN)r3   r4   r5   r1   r   r‡   r–   r`   r   Zdecorateri   r   rh   rs   r'   r'   r'   r(   rl   B  s    



rl   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   r7   rN   rl   r'   r'   r'   r(   Ú<module>   s&    &$' ?