o
    ð›hD  ã                   @   sÄ  d dl mZ d dlmZ d dlmZmZ d dlmZ d dlm	Z	 d dlm
Z
 d dlmZ d dlmZ d d	lmZmZmZ d d
lmZmZmZmZmZ d dlmZmZmZmZmZ d dlmZm Z m!Z! d dl"m#Z#m$Z$ d dl%m&Z& d dlm'Z' d dl(m)Z) d dl*m+Z+ d dl,m-Z- G dd„ deƒZ.G dd„ deƒZ/G dd„ dƒZ0G dd„ de0e/ed�Z1G dd„ deƒZ2G dd„ de1ƒZ3G d d!„ d!e#e$ƒZ4G d"d#„ d#e4ƒZ5G d$d%„ d%e4ƒZ6G d&d'„ d'e0eƒZ7d(d)„ Z8d*S )+é    )Útree)Údebug)Úinference_state_method_cacheÚCachedMetaClass)Úcompiled)Ú	recursion)Ú
docstrings)Úflow_analysis©ÚTreeSignature)ÚParserTreeFilterÚFunctionExecutionFilterÚ AnonymousFunctionExecutionFilter)Ú	ValueNameÚAbstractNameDefinitionÚAnonymousParamNameÚ	ParamNameÚNameWrapper)ÚContextualizedNodeÚ	NO_VALUESÚValueSetÚ	TreeValueÚValueWrapper)ÚLazyKnownValuesÚLazyKnownValueÚLazyTreeValue)ÚValueContextÚTreeContextMixin)Úiterable)Úparser_utils)Úget_yield_exprs)Úvalues_from_qualified_names©ÚTupleGenericManagerc                   @   s0   e Zd ZdZdZdd„ Zedd„ ƒZdd„ Zd	S )
Ú
LambdaNamez<lambda>Úfunctionc                 C   s   || _ |j| _d S ©N)Ú_lambda_valueÚparent_context)ÚselfZlambda_value© r*   úSc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/value/function.pyÚ__init__   s   zLambdaName.__init__c                 C   s
   | j jjS r&   )r'   Ú	tree_nodeÚ	start_pos©r)   r*   r*   r+   r.   "   s   
zLambdaName.start_posc                 C   s   t | jgƒS r&   )r   r'   r/   r*   r*   r+   Úinfer&   s   zLambdaName.inferN)	Ú__name__Ú
__module__Ú__qualname__Ústring_nameÚapi_typer,   Úpropertyr.   r0   r*   r*   r*   r+   r$      s    
r$   c                   @   s   e Zd Zdd„ ZdS )ÚFunctionAndClassBasec                 C   sF   | j  ¡ r| j  ¡ }|d u rd S ||  ¡ f S | j  ¡ r!|  ¡ fS d S r&   )r(   Úis_classÚget_qualified_namesÚ
py__name__Z	is_module)r)   Únr*   r*   r+   r9   +   s   



z(FunctionAndClassBase.get_qualified_namesN)r1   r2   r3   r9   r*   r*   r*   r+   r7   *   s    r7   c                   @   sj   e Zd ZdZddd„Zdd„ Zdd„ Zed	d
„ ƒZdd„ Z	dd„ Z
ddd„Zdd„ Zddd„Zdd„ ZdS )ÚFunctionMixinr%   Nc                 c   s.   � |   ¡ }| ¡ D ]}|j|d�E d H  q	d S )N)Úorigin_scope)Úpy__class__Zexecute_with_valuesÚget_filters)r)   r=   ÚclsÚinstancer*   r*   r+   r?   ;   s
   €ÿzFunctionMixin.get_filtersc                 C   s4   ddl m} |d u rt| gƒS t||| ¡ | ƒgƒS )Nr   )ÚBoundMethod)Zjedi.inference.value.instancerB   r   Ú
as_context)r)   rA   Zclass_valuerB   r*   r*   r+   Ú	py__get__@   s   
zFunctionMixin.py__get__c                    s   ‡ fdd„ˆ j  ¡ D ƒS )Nc                    s   g | ]}t ˆ |jƒ‘qS r*   )r   Úname©Ú.0Úparamr/   r*   r+   Ú
<listcomp>H   s    ÿz1FunctionMixin.get_param_names.<locals>.<listcomp>)r-   Ú
get_paramsr/   r*   r/   r+   Úget_param_namesG   s   
ÿzFunctionMixin.get_param_namesc                 C   s"   | j jdkr
t| ƒS t| | j jƒS )NÚlambdef)r-   Útyper$   r   rE   r/   r*   r*   r+   rE   K   s   zFunctionMixin.namec                 C   s   dS )NTr*   r/   r*   r*   r+   Úis_functionQ   ó   zFunctionMixin.is_functionc                 C   s   | j jS r&   )rE   r4   r/   r*   r*   r+   r:   T   s   zFunctionMixin.py__name__Tc                    sš   | j j}|d u r3dd„ ‰ |  ¡ }| ¡ }| ¡ }|  ¡ dd ‡ fdd„| ¡ D ƒ¡  }|d u r2|S n|jdd�}|  ¡ | j j	d	 jdd� }|d
 | S )Nc                 S   sJ   | j }|  ¡  ¡ }|d ur|d| 7 }| jd ur#|d| jjdd� 7 }|S )Nz: ú=F©Zinclude_prefix)r4   r0   Úget_type_hintÚdefault_nodeÚget_code)r;   ÚsÚ
annotationr*   r*   r+   Úparam_name_to_strZ   s   
z6FunctionMixin.get_type_hint.<locals>.param_name_to_strz(%s)ú, c                    ó   g | ]}ˆ |ƒ‘qS r*   r*   )rG   r;   ©rW   r*   r+   rI   f   s    ÿÿz/FunctionMixin.get_type_hint.<locals>.<listcomp>FrQ   é   z -> )
r-   rV   rC   r0   rR   r:   ÚjoinrK   rT   Úchildren)r)   Úadd_class_infoÚreturn_annotationÚfunction_executionÚresultZreturn_hintÚbodyr*   rZ   r+   rR   W   s   	þÿzFunctionMixin.get_type_hintc                 C   s   |   |¡}| ¡ S r&   )rC   r0   )r)   Ú	argumentsr`   r*   r*   r+   Ú
py__call__r   s   
zFunctionMixin.py__call__c                 C   s   |d u rt | ƒS t| |ƒS r&   )ÚAnonymousFunctionExecutionÚFunctionExecutionContext)r)   rc   r*   r*   r+   Ú_as_contextv   s   
zFunctionMixin._as_contextc                 C   s   dd„ |   ¡ D ƒS )Nc                 S   s   g | ]}t |ƒ‘qS r*   r
   ©rG   Úfr*   r*   r+   rI   |   ó    z0FunctionMixin.get_signatures.<locals>.<listcomp>)Úget_signature_functionsr/   r*   r*   r+   Úget_signatures{   ó   zFunctionMixin.get_signaturesr&   ©T)r1   r2   r3   r5   r?   rD   rK   r6   rE   rN   r:   rR   rd   rg   rl   r*   r*   r*   r+   r<   8   s    



r<   c                   @   s0   e Zd Zedd„ ƒZdd„ Zdd„ Zdd„ Zd	S )
ÚFunctionValuec                    sx   ‡ ‡‡fdd„‰t tˆ|ƒƒ}ˆ‰ˆ ¡ sˆ ¡ r$ˆj‰ˆ ¡ sˆ ¡ sˆ|ƒ}|r:t|t t‡fdd„|D ƒƒƒƒS |S )Nc                    s*   ˆ  ¡ rtˆjˆˆ| d�S ˆ ˆjˆ| d�S )N)r(   r-   )r8   ÚMethodValueÚinference_state)r-   )r@   Úcontextr(   r*   r+   Úcreate‚   s   üýz*FunctionValue.from_context.<locals>.createc                    rY   r*   r*   rh   )rs   r*   r+   rI   �   rj   z.FunctionValue.from_context.<locals>.<listcomp>)ÚlistÚ_find_overload_functionsr8   Zis_instancer(   ÚOverloadedFunctionValueÚreversed)r@   rr   r-   Zoverloaded_funcsr%   r*   )r@   rr   rs   r(   r+   Úfrom_context€   s   ÿýzFunctionValue.from_contextc                 C   s   t | jddƒ\}|S )NÚtypesÚFunctionType)r!   rq   )r)   Úcr*   r*   r+   r>   ¡   s   zFunctionValue.py__class__c                 C   ó   | j S r&   )r(   r/   r*   r*   r+   Úget_default_param_context¥   ó   z'FunctionValue.get_default_param_contextc                 C   s   | gS r&   r*   r/   r*   r*   r+   rk   ¨   r~   z%FunctionValue.get_signature_functionsN)r1   r2   r3   Úclassmethodrx   r>   r}   rk   r*   r*   r*   r+   ro      s    
 ro   )Ú	metaclassc                       s$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )ÚFunctionNameInClassc                    s   t ƒ  |¡ || _d S r&   )Úsuperr,   Ú_class_context)r)   Úclass_contextrE   ©Ú	__class__r*   r+   r,   ­   ó   
zFunctionNameInClass.__init__c                 C   ó
   | j  ¡ S r&   )rƒ   Ú	get_valuer/   r*   r*   r+   Úget_defining_qualified_value±   ó   
z0FunctionNameInClass.get_defining_qualified_value)r1   r2   r3   r,   rŠ   Ú__classcell__r*   r*   r…   r+   r�   ¬   s    r�   c                       s<   e Zd Z‡ fdd„Zdd„ Zdd„ Ze‡ fdd„ƒZ‡  ZS )	rp   c                    s$   t ƒ j|g|¢R i |¤Ž || _d S r&   )r‚   r,   r„   )r)   rq   r„   ÚargsÚkwargsr…   r*   r+   r,   ¶   s   
zMethodValue.__init__c                 C   r|   r&   )r„   r/   r*   r*   r+   r}   º   r~   z%MethodValue.get_default_param_contextc                 C   s$   | j  ¡ }|d u rd S ||  ¡ f S r&   )r„   r9   r:   )r)   Únamesr*   r*   r+   r9   ½   s   
zMethodValue.get_qualified_namesc                    s   t | jtƒ jƒS r&   )r�   r„   r‚   rE   r/   r…   r*   r+   rE   Å   s   zMethodValue.name)	r1   r2   r3   r,   r}   r9   r6   rE   rŒ   r*   r*   r…   r+   rp   µ   s    rp   c                   @   sl   e Zd Zdd„ Zeed�e ¡ ddd„ƒƒZdd„ Z	eje
g ƒd�dd	d
„ƒZddd„Zdd„ Zdd„ ZdS )ÚBaseFunctionExecutionContextc                 C   s   t ‚r&   )ÚNotImplementedErrorr/   r*   r*   r+   Úinfer_annotationsË   rO   z.BaseFunctionExecutionContext.infer_annotations)ÚdefaultFc           	   	   C   s  | j }|jdkr|  |jd ¡S |rt}t| j|ƒ}n|  ¡ }|r#|S |t 	| j
¡O }| ¡ }|D ][}|rE|t dd„ |  |¡D ƒ¡O }q1t | ||¡}|tju rXt d|¡ n&z|j}W n tyt   t | jd¡}|t|gƒO }Y n
w ||  |d ¡O }|tju rŒt d|¡  |S q1|S )	NrL   éÿÿÿÿc                 s   ó   � | ]}|  ¡ V  qd S r&   ©r0   ©rG   Ú
lazy_valuer*   r*   r+   Ú	<genexpr>ã   ó
   € ÿ
ÿzABaseFunctionExecutionContext.get_return_values.<locals>.<genexpr>zReturn unreachable: %sÚNoneé   zReturn reachable: %s)r-   rM   Z
infer_noder]   r   r    rq   r’   r   Úinfer_return_typesÚ_valueZiter_return_stmtsr   Ú	from_setsÚ_get_yield_lazy_valuer	   Zreachability_checkZUNREACHABLEr   ÚdbgÚAttributeErrorr   Úbuiltin_from_nameZ	REACHABLE)	r)   Úcheck_yieldsÚfuncdefZ	value_setÚreturnsÚrÚcheckr]   Úctxr*   r*   r+   Úget_return_valuesÎ   s@   
þ

þ
ýz.BaseFunctionExecutionContext.get_return_valuesc                 c   st   � |j dkrt | jd¡}t|ƒV  d S |jd }|j dkr2t| |jd ƒ}| ¡  |¡E d H  d S t	| |ƒV  d S )NÚkeywordr›   rœ   Z	yield_arg)
rM   r   r£   rq   r   r]   r   r0   Úiterater   )r)   Z
yield_exprr©   ÚnodeÚcnr*   r*   r+   r    ø   s   €



z2BaseFunctionExecutionContext._get_yield_lazy_valuec              
   c   s¢  � dd„ t | j| jƒD ƒ}g }d }|D ]Z\}}|j}|jdkr"|j}|jdkrH|| jkrHt |¡rH||kr?|d d  |¡ n,| ||gf¡ n#|| jkrV| d |gf¡ n| jdd�}|rht	|d	t
d
ƒd�V   d S |}q|D ]^\}}	|d u r†|	D ]
}|  |¡E d H  qzqp| ¡ }
t| |
ƒ}| ¡  |¡}t|ƒ}|D ]1}t|jd jƒ| ¡ i}|  ||¡� |	D ]
}|  |¡E d H  q³W d   ƒ n1 sÈw   Y  qœqpd S )Nc              
   S   s"   g | ]}|t  |d ddd¡f‘qS )Úfor_stmtr¥   Z
while_stmtZif_stmt)r   Zsearch_ancestor)rG   Úyr*   r*   r+   rI   	  s
    þ
ÿzFBaseFunctionExecutionContext.get_yield_lazy_values.<locals>.<listcomp>Zsuiter¯   r”   rœ   T)r¤   r   Úinf)ÚminÚmax)r    rq   r-   ÚparentrM   r   Zfor_stmt_defines_one_nameÚappendrª   r   Úfloatr    Zget_testlistr   r0   r¬   rt   Ústrr]   ÚvalueZpredefine_names)r)   Úis_asyncZfor_parentsZyields_orderZlast_for_stmtZyield_r¯   r´   ry   ZyieldsZ
input_noder®   Zorderedr˜   ÚdctZyield_in_same_for_stmtr*   r*   r+   Úget_yield_lazy_values  sT   €þ
ÿ
ÿ
ÿÿ€þöz2BaseFunctionExecutionContext.get_yield_lazy_valuesc                 C   s   t  dd„ |  ¡ D ƒ¡S )Nc                 s   r•   r&   r–   r—   r*   r*   r+   r™   6  rš   zBBaseFunctionExecutionContext.merge_yield_values.<locals>.<genexpr>)r   rŸ   r»   )r)   r¹   r*   r*   r+   Úmerge_yield_values5  s   
þz/BaseFunctionExecutionContext.merge_yield_valuesc                 C   s   t t| j| jƒƒS r&   )Úboolr    rq   r-   r/   r*   r*   r+   Úis_generator;  rm   z)BaseFunctionExecutionContext.is_generatorc                    sÔ   | j }| jjjdv }ddlm‰  |rU|  ¡ r6|j d¡}| j	dd�}| 
¡ tf‰t‡ ‡fdd„|D ƒƒ ¡ S |j d	¡}|  ¡ }| 
¡ ttf‰t‡ ‡fd
d„|D ƒƒ ¡ S |  ¡ rf|  ¡ sftt || ¡gƒS |  ¡ S )z4
        Created to be used by inheritance.
        )Z
async_stmtZasync_funcdefr   )ÚGenericClassÚAsyncGeneratorT)r¹   c                 3   ó   � | ]
}ˆ |t ˆƒƒV  qd S r&   r"   ©rG   r{   ©r¿   Zgenericsr*   r+   r™   N  s
   € ÿ
ÿz5BaseFunctionExecutionContext.infer.<locals>.<genexpr>Ú	Coroutinec                 3   rÁ   r&   r"   rÂ   rÃ   r*   r+   r™   W  s   € 
ÿ)rq   r-   r´   rM   Zjedi.inference.gradual.baser¿   r¾   Ztyping_moduleZpy__getattribute__r¼   r>   r   r   Zexecute_annotationrª   r’   r   Ú	Generator)r)   rq   Zis_coroutineZasync_generator_classesZyield_valuesZasync_classesZreturn_valuesr*   rÃ   r+   r0   >  s4   ÿþýÿþz"BaseFunctionExecutionContext.inferN)F)r1   r2   r3   r’   r   r   r   Zexecution_recursion_decoratorrª   r    Úiterr»   r¼   r¾   r0   r*   r*   r*   r+   r�   Ê   s    (
.r�   c                       s6   e Zd Z‡ fdd„Zd
dd„Zdd„ Zdd	„ Z‡  ZS )rf   c                    ó   t ƒ  |¡ || _d S r&   )r‚   r,   Ú
_arguments)r)   Zfunction_valuerc   r…   r*   r+   r,   c  r‡   z!FunctionExecutionContext.__init__Nc                 c   s   � t | | j||| jd�V  d S )N)Úuntil_positionr=   rc   )r   rž   rÈ   ©r)   rÉ   r=   r*   r*   r+   r?   g  s   €üz$FunctionExecutionContext.get_filtersc                 C   s   ddl m} || j| jƒS )Nr   )r�   )Z!jedi.inference.gradual.annotationr�   rž   rÈ   )r)   r�   r*   r*   r+   r’   o  s   z*FunctionExecutionContext.infer_annotationsc                    s   ‡ fdd„ˆ j j ¡ D ƒS )Nc                    s   g | ]}t ˆ j|jˆ jƒ‘qS r*   )r   rž   rE   rÈ   rF   r/   r*   r+   rI   t  s    ÿÿz<FunctionExecutionContext.get_param_names.<locals>.<listcomp>)rž   r-   rJ   r/   r*   r/   r+   rK   s  s   

þz(FunctionExecutionContext.get_param_names©NN)r1   r2   r3   r,   r?   r’   rK   rŒ   r*   r*   r…   r+   rf   b  s
    
rf   c                   @   s&   e Zd Zdd„ Zddd„Zdd„ ZdS )	re   c                 C   s   t S r&   )r   r/   r*   r*   r+   r’   {  s   z,AnonymousFunctionExecution.infer_annotationsNc                 c   s   � t | | j||d�V  d S )N)rÉ   r=   )r   rž   rÊ   r*   r*   r+   r?   €  s   €ýz&AnonymousFunctionExecution.get_filtersc                 C   rˆ   r&   )rž   rK   r/   r*   r*   r+   rK   ‡  r‹   z*AnonymousFunctionExecution.get_param_namesrË   )r1   r2   r3   r’   r?   rK   r*   r*   r*   r+   re   z  s    
re   c                       s6   e Zd Z‡ fdd„Zdd„ Zdd„ Zd
dd	„Z‡  ZS )rv   c                    rÇ   r&   )r‚   r,   Ú_overloaded_functions)r)   r%   Zoverloaded_functionsr…   r*   r+   r,   Œ  r‡   z OverloadedFunctionValue.__init__c                 C   sp   t jd| jdd� g }|  ¡ D ]}|j |¡}| |¡ | |¡r'| ¡   S q| j	j
r.tS t dd„ |D ƒ¡S )NzExecute overloaded function %sZBLUE)Úcolorc                 s   r•   r&   r–   )rG   Zfer*   r*   r+   r™   œ  ó   € z5OverloadedFunctionValue.py__call__.<locals>.<genexpr>)r   r¡   Z_wrapped_valuerl   r¸   rC   rµ   Zmatches_signaturer0   rq   Zis_analysisr   r   rŸ   )r)   rc   Zfunction_executionsÚ	signaturer`   r*   r*   r+   rd   �  s   

ÿz"OverloadedFunctionValue.py__call__c                 C   r|   r&   )rÌ   r/   r*   r*   r+   rk   ž  r~   z/OverloadedFunctionValue.get_signature_functionsTc                 C   s   dd  dd„ | jD ƒ¡ S )Nz	Union[%s]rX   c                 s   r•   r&   )rR   rh   r*   r*   r+   r™   ¢  rÎ   z8OverloadedFunctionValue.get_type_hint.<locals>.<genexpr>)r\   rÌ   )r)   r^   r*   r*   r+   rR   ¡  s   z%OverloadedFunctionValue.get_type_hintrn   )r1   r2   r3   r,   rd   rk   rR   rŒ   r*   r*   r…   r+   rv   ‹  s
    rv   c                 c   sš   � dd„ }|j dkrd S ||ƒr|V  	 t| |jd�}| |jj¡}t|tƒs)J ‚|s-d S d}|D ]}|jj	}|j dkrG||ƒrG|}d}|V  q1|sLd S q)Nc                 S   sb   | j jdkr/| j jd }|jdkr|g}n|j}|D ]}|jd }|jdkr.|jdkr. dS qdS )	NZ	decoratedr   Ú	decoratorrœ   rE   ÚoverloadTF)r´   rM   r]   r¸   )r¥   Z
decoratorsrÐ   Zdotted_namer*   r*   r+   Ú_is_overload_decorated¦  s   

€z8_find_overload_functions.<locals>._is_overload_decoratedrL   T)rÉ   Fr¥   )
rM   r   r.   ÚgetrE   r¸   Ú
isinstancert   Z	tree_namer´   )rr   r-   rÒ   Úfilterr�   ÚfoundrE   r¥   r*   r*   r+   ru   ¥  s4   €
þ€íru   N)9Zparso.pythonr   Zjedir   Zjedi.inference.cacher   r   Zjedi.inferencer   r   r   r	   Zjedi.inference.signaturer   Zjedi.inference.filtersr   r   r   Zjedi.inference.namesr   r   r   r   r   Zjedi.inference.base_valuer   r   r   r   r   Zjedi.inference.lazy_valuer   r   r   Zjedi.inference.contextr   r   Zjedi.inference.valuer   r   Zjedi.inference.parser_cacher    Zjedi.inference.helpersr!   Zjedi.inference.gradual.genericsr#   r$   r7   r<   ro   r�   rp   r�   rf   re   rv   ru   r*   r*   r*   r+   Ú<module>   s<    G-	 