o
    ˷e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)selflambda_value r+   T/var/www/ideatree/venv/lib/python3.10/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'   r0   r+   r+   r,   infer&   s   zLambdaName.inferN)	__name__
__module____qualname__string_nameapi_typer-   propertyr/   r1   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__	is_module)r)   nr+   r+   r,   r:   +   s   



z(FunctionAndClassBase.get_qualified_namesN)r2   r3   r4   r:   r+   r+   r+   r,   r8   *   s    r8   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__execute_with_valuesget_filters)r)   r?   clsinstancer+   r+   r,   rB   ;   s
   zFunctionMixin.get_filtersc                 C   s4   ddl m} |d u rt| gS t||| | gS )Nr   )BoundMethod)jedi.inference.value.instancerE   r   
as_context)r)   rD   class_valuerE   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paramr0   r+   r,   
<listcomp>H   s    z1FunctionMixin.get_param_names.<locals>.<listcomp>)r.   
get_paramsr0   r+   r0   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   rJ   r0   r+   r+   r,   rJ   K   s   zFunctionMixin.namec                 C   s   dS )NTr+   r0   r+   r+   r,   is_functionQ      zFunctionMixin.is_functionc                 C   s   | j jS r&   )rJ   r5   r0   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include_prefix)r5   r1   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+   )rL   r=   r]   r+   r,   rN   f   s    z/FunctionMixin.get_type_hint.<locals>.<listcomp>FrV      z -> )
r.   r\   rG   r1   rX   r;   joinrP   rZ   children)r)   add_class_inforeturn_annotationfunction_executionresultreturn_hintbodyr+   r`   r,   rX   W   s   	zFunctionMixin.get_type_hintc                 C   s   |  |}| S r&   )rG   r1   )r)   	argumentsrf   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)   rj   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
   rL   fr+   r+   r,   rN   |       z0FunctionMixin.get_signatures.<locals>.<listcomp>)get_signature_functionsr0   r+   r+   r,   get_signatures{      zFunctionMixin.get_signaturesr&   T)r2   r3   r4   r6   rB   rI   rP   r7   rJ   rS   r;   rX   rk   rn   rs   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.   )r9   MethodValueinference_state)r.   )rC   contextr(   r+   r,   create   s   z*FunctionValue.from_context.<locals>.createc                    r_   r+   r+   ro   )rz   r+   r,   rN      rq   z.FunctionValue.from_context.<locals>.<listcomp>)list_find_overload_functionsr9   is_instancer(   OverloadedFunctionValuereversed)rC   ry   r.   overloaded_funcsr%   r+   )rC   ry   rz   r(   r,   from_context   s   zFunctionValue.from_contextc                 C   s   t | jdd\}|S )NtypesFunctionType)r!   rx   )r)   cr+   r+   r,   r@      s   zFunctionValue.py__class__c                 C      | j S r&   )r(   r0   r+   r+   r,   get_default_param_context      z'FunctionValue.get_default_param_contextc                 C   s   | gS r&   r+   r0   r+   r+   r,   rr      r   z%FunctionValue.get_signature_functionsN)r2   r3   r4   classmethodr   r@   r   rr   r+   r+   r+   r,   rv      s    
 rv   )	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_contextrJ   	__class__r+   r,   r-         
zFunctionNameInClass.__init__c                 C   
   | j  S r&   )r   	get_valuer0   r+   r+   r,   get_defining_qualified_value      
z0FunctionNameInClass.get_defining_qualified_value)r2   r3   r4   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 )	rw   c                    s$   t  j|g|R i | || _d S r&   )r   r-   r   )r)   rx   r   argskwargsr   r+   r,   r-      s   
zMethodValue.__init__c                 C   r   r&   )r   r0   r+   r+   r,   r      r   z%MethodValue.get_default_param_contextc                 C   s$   | j  }|d u rd S ||  f S r&   )r   r:   r;   )r)   namesr+   r+   r,   r:      s   
zMethodValue.get_qualified_namesc                    s   t | jt jS r&   )r   r   r   rJ   r0   r   r+   r,   rJ      s   zMethodValue.name)	r2   r3   r4   r-   r   r:   r7   rJ   r   r+   r+   r   r,   rw      s    rw   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&   )NotImplementedErrorr0   r+   r+   r,   infer_annotations   rT   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 rtd|  |S q1|S )	NrQ   c                 s       | ]}|  V  qd S r&   r1   rL   
lazy_valuer+   r+   r,   	<genexpr>   
    
zABaseFunctionExecutionContext.get_return_values.<locals>.<genexpr>zReturn unreachable: %sNone   zReturn reachable: %s)r.   rR   
infer_noderc   r   r    rx   r   r   infer_return_types_valueiter_return_stmtsr   	from_sets_get_yield_lazy_valuer	   reachability_checkUNREACHABLEr   dbgAttributeErrorr   builtin_from_name	REACHABLE)	r)   check_yieldsfuncdef	value_setreturnsrcheckrc   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   	yield_arg)
rR   r   r   rx   r   rc   r   r1   iterater   )r)   
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  qW d    n1 sw   Y  qqpd S )Nc              
   S   s"   g | ]}|t |d dddfqS )for_stmtr   
while_stmtif_stmt)r   search_ancestor)rL   yr+   r+   r,   rN   	  s
    
zFBaseFunctionExecutionContext.get_yield_lazy_values.<locals>.<listcomp>suiter   r   r   T)r   r   inf)minmax)r    rx   r.   parentrR   r   for_stmt_defines_one_nameappendr   r   floatr   get_testlistr   r1   r   r{   strrc   valuepredefine_names)r)   is_asyncfor_parentsyields_orderlast_for_stmtyield_r   r   r   yields
input_noder   orderedr   dct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    rx   r.   r0   r+   r+   r,   is_generator;  rt   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.
        )
async_stmtasync_funcdefr   )GenericClassAsyncGeneratorT)r   c                 3       | ]
} |t V  qd S r&   r"   rL   r   r   genericsr+   r,   r   N  s
    
z5BaseFunctionExecutionContext.infer.<locals>.<genexpr>	Coroutinec                 3   r   r&   r"   r   r   r+   r,   r   W  s    
)rx   r.   r   rR   jedi.inference.gradual.baser   r   typing_modulepy__getattribute__r   r@   r   r   execute_annotationr   r   r   	Generator)r)   rx   is_coroutineasync_generator_classesyield_valuesasync_classesreturn_valuesr+   r   r,   r1   >  s4   z"BaseFunctionExecutionContext.inferN)F)r2   r3   r4   r   r   r   r   execution_recursion_decoratorr   r   iterr   r   r   r1   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 )rm   c                       t  | || _d S r&   )r   r-   
_arguments)r)   function_valuerj   r   r+   r,   r-   c  r   z!FunctionExecutionContext.__init__Nc                 c   s    t | | j||| jdV  d S )N)until_positionr?   rj   )r   r   r   r)   r   r?   r+   r+   r,   rB   g  s   z$FunctionExecutionContext.get_filtersc                 C   s   ddl m} || j| jS )Nr   )r   )!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   rJ   r   rK   r0   r+   r,   rN   t  s    z<FunctionExecutionContext.get_param_names.<locals>.<listcomp>)r   r.   rO   r0   r+   r0   r,   rP   s  s   

z(FunctionExecutionContext.get_param_namesNN)r2   r3   r4   r-   rB   r   rP   r   r+   r+   r   r,   rm   b  s
    
rm   c                   @   s&   e Zd Zdd ZdddZdd ZdS )	rl   c                 C   s   t S r&   )r   r0   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,   rB     s   z&AnonymousFunctionExecution.get_filtersc                 C   r   r&   )r   rP   r0   r+   r+   r,   rP     r   z*AnonymousFunctionExecution.get_param_namesr   )r2   r3   r4   r   rB   rP   r+   r+   r+   r,   rl   z  s    
rl   c                       s6   e Zd Z fddZdd Zdd Zd
dd	Z  ZS )r~   c                    r   r&   )r   r-   _overloaded_functions)r)   r%   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 %sBLUE)colorc                 s   r   r&   r   )rL   fer+   r+   r,   r         z5OverloadedFunctionValue.py__call__.<locals>.<genexpr>)r   r   _wrapped_valuers   r   rG   r   matches_signaturer1   rx   is_analysisr   r   r   )r)   rj   function_executions	signaturerf   r+   r+   r,   rk     s   

z"OverloadedFunctionValue.py__call__c                 C   r   r&   )r   r0   r+   r+   r,   rr     r   z/OverloadedFunctionValue.get_signature_functionsTc                 C   s   dd dd | jD  S )Nz	Union[%s]r^   c                 s   r   r&   )rX   ro   r+   r+   r,   r     r   z8OverloadedFunctionValue.get_type_hint.<locals>.<genexpr>)rb   r   )r)   rd   r+   r+   r,   rX     s   z%OverloadedFunctionValue.get_type_hintru   )r2   r3   r4   r-   rk   rr   rX   r   r+   r+   r   r,   r~     s
    r~   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 )	N	decoratedr   	decoratorr   rJ   overloadTF)r   rR   rc   r   )r   
decoratorsr  dotted_namer+   r+   r,   _is_overload_decorated  s   

z8_find_overload_functions.<locals>._is_overload_decoratedrQ   T)r   Fr   )
rR   r   r/   getrJ   r   
isinstancer{   	tree_namer   )ry   r.   r  filterr   foundrJ   r   r+   r+   r,   r|     s4   
r|   N)9parso.pythonr   jedir   jedi.inference.cacher   r   jedi.inferencer   r   r   r	   jedi.inference.signaturer   jedi.inference.filtersr   r   r   jedi.inference.namesr   r   r   r   r   jedi.inference.base_valuer   r   r   r   r   jedi.inference.lazy_valuer   r   r   jedi.inference.contextr   r   jedi.inference.valuer   r   jedi.inference.parser_cacher    jedi.inference.helpersr!   jedi.inference.gradual.genericsr#   r$   r8   r>   rv   r   rw   r   rm   rl   r~   r|   r+   r+   r+   r,   <module>   s<    G-	 