o
    ï›hÒ(  ã                   @   sœ   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 d dlmZ d	d
„ ZG dd„ deƒZdd„ Zdd„ Zdd„ ZdS )é    )Údefaultdict)Ú	Parameter)Údebug)ÚPushBackIterator)Úanalysis)ÚLazyKnownValueÚLazyTreeValueÚLazyUnknownValue)Úiterable)Ú	ParamNamec                 C   s8   t |tƒr|j}|jjdkr|j}t |j| ||¡S d S )NÚargument)Ú
isinstancer   ÚdataÚparentÚtyper   ÚaddÚcontext)Z
error_nameÚ
lazy_valueÚmessageÚnode© r   úJc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/param.pyÚ_add_argument_issue   s   
ür   c                       s6   e Zd Zd
‡ fdd„	Zdd„ Zdd„ Zdd	„ Z‡  ZS )ÚExecutedParamNameFc                    s$   t ƒ j||j|d� || _|| _d S )N)Ú	arguments)ÚsuperÚ__init__ÚnameÚ_lazy_valueÚ_is_default)ÚselfÚfunction_valuer   Z
param_noder   Ú
is_default©Ú	__class__r   r   r      s   
zExecutedParamName.__init__c                 C   s
   | j  ¡ S ©N)r   Úinfer©r    r   r   r   r&      s   
zExecutedParamName.inferc                    sp   | j rdS |  ¡  ¡ }|  ¡ tjtjfv rdS | jdd�‰ ˆ s!dS t‡ fdd„|D ƒƒ}t	j
d||ˆ dd� |S )	NTF)Zexecute_annotationc                 3   s(   � | ]}ˆ   ¡ D ]}| |¡V  qqd S r%   )Zgather_annotation_classesZis_sub_class_of)Ú.0Úc1Úc2©Úannotationsr   r   Ú	<genexpr>)   s   € þþz6ExecutedParamName.matches_signature.<locals>.<genexpr>zparam compare %s: %s <=> %sZBLUE)Úcolor)r   r&   Zpy__class__Zget_kindr   ÚVAR_POSITIONALÚVAR_KEYWORDZinfer_annotationÚanyr   Zdbg)r    Zargument_valuesÚmatchesr   r+   r   Úmatches_signature   s   ÿÿz#ExecutedParamName.matches_signaturec                 C   s   d| j j| jf S )Nz<%s: %s>)r$   Ú__name__Zstring_namer'   r   r   r   Ú__repr__0   s   zExecutedParamName.__repr__)F)r4   Ú
__module__Ú__qualname__r   r&   r3   r5   Ú__classcell__r   r   r#   r   r      s
    r   c              
      sŒ  ‡ ‡‡‡fdd„}g ‰g }i }| j ‰|  ¡ }ˆ ¡ D ]}|||jj< qtˆ  ˆ¡ƒ‰ttˆƒƒ}t	dd„ ƒ}i }	d}
d}ˆ ¡ D �]}d}t
|dƒ\}}|dur�d}
z|| }W n tye   |||< Y n-w ||	v r‰d}d	ˆj|f }ˆ  ¡ D ]}ˆ tj|jd
|j|d�¡ qwn	t| ˆ ||ƒ|	|< t
|dƒ\}}|dusPz| |	|jj ¡ W q@ ty±   Y nw |jdkråg }|durÙ| |¡ |D ]\}}|rÓ| ||f¡  n| |¡ qÄt | j|¡}t|ƒ}nX|jdk�r|duró||ƒ t | jt|ƒ¡}t|ƒ}i }n:|du �r;|jdu �r2tƒ }|
�s1ˆ  ¡ D ]}tˆtˆƒƒ}ˆ tj|jd|j|d�¡ �qnt||jƒ}d}n|}| t| ˆ |||d�¡ t |tƒ�sW|d |	|jj< q@|
�r–t!|ƒt!|	ƒ D ]2}|| }|�s”|�s”|j�s”|j�s”ˆ  ¡ D ]}tˆtˆƒƒ}ˆ tj|jd|j|d�¡ �q{�qc| "¡ D ]\}}dˆj|f }ˆ t#d||d�¡ �qšt|ƒ}|�rÂ|d \}}||ƒ |ˆfS )aÀ  
    Return a tuple of:
      - a list of `ExecutedParamName`s corresponding to the arguments of the
        function execution `function_value`, containing the inferred value of
        those arguments (whether explicit or default)
      - a list of the issues encountered while building that list

    For example, given:
    ```
    def foo(a, b, c=None, d='d'): ...

    foo(42, c='c')
    ```

    Then for the execution of `foo`, this will return a tuple containing:
      - a list with entries for each parameter a, b, c & d; the entries for a,
        c, & d will have their values (42, 'c' and 'd' respectively) included.
      - a list with a single entry about the lack of a value for `b`
    c                    sH   t ˆtˆƒƒ}ˆ  ¡ rˆ td| |d�¡ d S ˆ d ¡ t d|¡ d S )Nztype-error-too-many-arguments©r   znon-public warning: %s)Ú_error_argument_countÚlenÚget_calling_nodesÚappendr   r   Úwarning)r   Úm©r   ÚfuncdefZissuesZunpacked_var   r   Útoo_many_argsH   s   ýÿ
z:get_executed_param_names_and_issues.<locals>.too_many_argsc                   S   s   g S r%   r   r   r   r   r   Ú<lambda>g   s    z5get_executed_param_names_and_issues.<locals>.<lambda>F)NNNTz>TypeError: %s() got multiple values for keyword argument '%s'.ztype-error-multiple-valuesr9   é   é   ztype-error-too-few-arguments)r"   éÿÿÿÿz8TypeError: %s() got an unexpected keyword argument '%s'.ztype-error-keyword-argumentr   )$Z	tree_nodeZget_default_param_contextÚ
get_paramsr   ÚvalueÚlistÚunpackr   Úiterr   ÚnextÚKeyErrorr<   r=   r   r   r   r   r   Ú
star_countZ	push_backr
   Z	FakeTupleZinference_stater   ZFakeDictÚdictÚdefaultr	   r:   r;   r   r   ÚsetÚitemsr   )r!   r   rB   Zresult_paramsZ
param_dictZdefault_param_contextÚparamZvar_arg_iteratorZnon_matching_keysZ	keys_usedZ	keys_onlyZhad_multiple_value_errorr"   Úkeyr   Z	key_paramr?   Zcontextualized_nodeZlazy_value_listÚseqZ
result_argÚdctÚkr   Zremaining_argumentsZ	first_keyr   r@   r   Ú#get_executed_param_names_and_issues4   sô   ÿÿþÿÿÿìÿ



üÿ€	
ÿ€ÿÿþÿ€ÿýÿrX   c                 C   s   t | |ƒd S )a|  
    Return a list of `ExecutedParamName`s corresponding to the arguments of the
    function execution `function_value`, containing the inferred value of those
    arguments (whether explicit or default). Any issues building this list (for
    example required arguments which are missing in the invocation) are ignored.

    For example, given:
    ```
    def foo(a, b, c=None, d='d'): ...

    foo(42, c='c')
    ```

    Then for the execution of `foo`, this will return a list containing entries
    for each parameter a, b, c & d; the entries for a, c, & d will have their
    values (42, 'c' and 'd' respectively) included.
    r   )rX   )r!   r   r   r   r   Úget_executed_param_namesã   s   rY   c                 C   sN   |   ¡ }tdd„ |D ƒƒ}|dkrd}ndt|ƒ|  }d| j|t|ƒ|f S )Nc                 s   s    � | ]}|j s
|jrd V  qdS )rD   N)rP   rN   )r(   Úpr   r   r   r-   ú   s   € z(_error_argument_count.<locals>.<genexpr>r   zexactly zfrom %s to z0TypeError: %s() takes %s%s arguments (%s given).)rG   Úsumr;   r   )rA   Zactual_countÚparamsZdefault_argumentsÚbeforer   r   r   r:   ø   s   ÿr:   N)Úcollectionsr   Úinspectr   Zjedir   Zjedi.inference.utilsr   Zjedi.inferencer   Zjedi.inference.lazy_valuer   r   r	   Zjedi.inference.valuer
   Zjedi.inference.namesr   r   r   rX   rY   r:   r   r   r   r   Ú<module>   s     0