a
    lc(                     @   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r4|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   P/var/www/html/django/DPS/env/lib/python3.9/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  sBd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    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)r5   
__module____qualname__r   r&   r4   r6   __classcell__r   r   r#   r   r      s   r   c              
      s   fdd}g g }i }| j |  } D ]}|||jj< q4t tt}t	dd }i }	d}
d} D ]:}d}t
|d\}}|dur8d}
z|| }W n ty   |||< Y n\0 ||	v rd}d	j|f }  D ] }tj|jd
|j|d qnt|  |||	|< t
|d\}}qz||	|jj  W qW n tyf   Y n0 |jdkrg }|dur|| |D ].\}}|r|||f  q|| qt| j|}t|}n|jdkr|dur|| t| jt|}t|}i }nt|du r|jdu rtt }|
s  D ]0}tt}tj|jd|j|d q@nt||j}d}n|}|t|  |||d t |ts|d |	|jj< q|
r:t!|t!|	 D ]d}|| }|s|s|js|jsԈ  D ]0}tt}tj|jd|j|d qq|" D ],\}}dj|f }t#d||d qBt|}|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                    sF   t t}  r,td| |d n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       z5get_executed_param_names_and_issues.<locals>.<lambda>F)NNNTz>TypeError: %s() got multiple values for keyword argument '%s'.ztype-error-multiple-valuesr:         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   rC   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   rA   r   #get_executed_param_names_and_issues4   s    







	

rZ   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   )rZ   )r!   r   r   r   r   get_executed_param_names   s    r[   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 )rF   N)rR   rP   )r(   pr   r   r   r-      rE   z(_error_argument_count.<locals>.<genexpr>r   zexactly zfrom %s to z0TypeError: %s() takes %s%s arguments (%s given).)rI   sumr<   r   )rB   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   rZ   r[   r;   r   r   r   r   <module>   s    0