a
    ÷£Be×  ã                   @   s‚   d 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„ Zd	d
„ Zdd„ Zdd„ Zeddd„ƒZG dd„ deƒZdS )a
  
This module is responsible for inferring *args and **kwargs for signatures.

This means for example in this case::

    def foo(a, b, c): ...

    def bar(*args):
        return foo(1, *args)

The signature here for bar should be `bar(b, c)` instead of bar(*args).
é    )Ú	Parameter)Útree)Úto_list)ÚParamNameWrapper)Úis_big_annoying_libraryc                 c   s  ddl m} ddlm} | j}t | jdd¡}| ¡ }|jd j	}|jd j
}| ¡  | j¡D ]¢}||j	  krx|k r^n q^|j}	|	jdkr^|	jd d| j kr^||	d	ƒ}
|
d ur^| |
¡}t| ||ƒr^t||
ƒ}|j|j||
jd
 |
d�}|D ]}||fV  qðq^d S )Nr   )Úsearch_ancestor)ÚTreeArgumentsZfuncdefZlambdeféÿÿÿÿÚargumentÚ*Útraileré   )ÚcontextZargument_noder   )Zparso.python.treer   Zjedi.inference.argumentsr   Úparent_contextr   Z	tree_nameZget_root_nodeÚchildrenÚ	start_posÚend_posZget_used_namesÚgetÚstring_nameÚparentÚtypeÚ
star_countZcreate_contextÚ_goes_to_param_nameÚ_to_callablesZcreate_cachedZinference_state)Ú
param_namer   r   Zexecution_contextZfunction_nodeZmodule_nodeÚstartÚendÚnamer
   r   r   ÚvaluesÚargsÚc© r!   ú[/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/jedi/inference/star_args.pyÚ_iter_nodes_for_param   s4    
ÿ


ür#   c                    s>   |j dkrdS ddlm} |||ƒ ¡ }t‡ fdd„|D ƒƒS )Nr   Fr   )ÚTreeNameDefinitionc                 3   s&   | ]}ˆ j |j koˆ j|jkV  qd S ©N)r   r   )Ú.0Úp©r   r!   r"   Ú	<genexpr>>   s   þz&_goes_to_param_name.<locals>.<genexpr>)r   Újedi.inference.namesr$   ZgotoÚany)r   r   Zpotential_namer$   Úfoundr!   r(   r"   r   9   s    
þr   c                 C   sd   ddl m} |j}|jd dk}|  |j| ¡}|j|d d … D ]}||krR q`|| ||ƒ}qB|S )Nr   )Úinfer_trailerÚawaitr   )Zjedi.inference.syntax_treer-   r   r   Z
infer_node)r   r   r-   Z	atom_exprÚindexr   Ztrailer2r!   r!   r"   r   C   s    r   c                 c   sv   d}t ƒ }|  ¡ D ]$\}}|d u r,|d7 }q| |¡ q|D ]4}|rV| ¡ rV|d8 }q<|j|v rj| ¡ rjq<|V  q<d S )Nr   r   )ÚsetÚunpackÚaddZmaybe_positional_argumentr   Zmaybe_keyword_argument)Ú	argumentsÚparam_namesÚcountZ	used_keysÚkeyÚ_r'   r!   r!   r"   Ú_remove_given_paramsQ   s    
r8   é   c              	   c   sr  | r t | d jƒr | E d H  d S tƒ }g }g }g }g }g }d }d }	| D ]Ô}
|
 ¡ }|tjkrr|d@ rpt|
ƒ}|
}qF|
 ¡ tjkrš|d@ r˜tt|
ƒƒ}|
}	qF|tj	kr¸|d@ r¶| 
|
¡ qF|tjkrÒ|d@ rÐ|
V  qF|dkrêt|
tjƒV  qF|dk�r| 
t|
tj	ƒ¡ qF| |
j¡ |
V  qFd}d}d}|D ]ê}|\}}|}||v �rR| |¡ nd}| ¡ D ]´}d}|dk�rtd}g }ttt||jdd�ƒƒ|ƒD ]d}
|
 ¡ tjk�r´| 
|
¡ nB|
 ¡ tjk�rÐ| 
|
¡ n&|
 ¡ tj	k�rì| 
|
¡ n
| 
|
¡ �q”t|ƒt|ƒk�r^|}�q^�q,|D ]R}
|dk�rJ|
 ¡ tjk�rJt|
tjƒV  n"|
 ¡ tjk�rf| |
j¡ |
V  �q|�sˆ|d u�rˆ|V  n|�r˜|d V  |D ]z\}}| ¡ D ]f}d}ttt||jdd�ƒƒdd	�D ]<}
|
 ¡ tjk�rò| 
|
¡ n|
 ¡ tj	k�rÒ| 
|
¡ �qÒ�q¬�qœ|D ](}
|
j|v �r0�q|
V  | |
j¡ �q|�s^|	d u�r^|	V  n|�rn|d V  d S )
Nr   r   é   r!   FTr9   )Zresolve_stars)r   )r   r   r0   Úget_kindr   ÚVAR_POSITIONALr#   ÚVAR_KEYWORDÚlistÚKEYWORD_ONLYÚappendÚPOSITIONAL_ONLYÚParamNameFixedKindr2   r   ÚremoveZget_signaturesÚprocess_paramsr8   Zget_param_namesÚlenÚPOSITIONAL_OR_KEYWORD)r4   r   Z
used_namesZarg_callablesZkwarg_callablesZkw_only_namesZkwarg_namesÚ	arg_namesZoriginal_arg_nameZoriginal_kwarg_namer'   ÚkindZlongest_param_namesZfound_arg_signatureZfound_kwarg_signatureZfunc_and_argumentÚfuncr3   Znew_star_countÚ	signatureZargs_for_this_funcr!   r!   r"   rD   c   sÂ    







þü


þü
rD   c                       s$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )rB   c                    s   t ƒ  |¡ || _d S r%   )ÚsuperÚ__init__Ú	_new_kind)Úselfr   Znew_kind©Ú	__class__r!   r"   rL   ×   s    zParamNameFixedKind.__init__c                 C   s   | j S r%   )rM   )rN   r!   r!   r"   r;   Û   s    zParamNameFixedKind.get_kind)Ú__name__Ú
__module__Ú__qualname__rL   r;   Ú__classcell__r!   r!   rO   r"   rB   Ö   s   rB   N)r9   )Ú__doc__Úinspectr   Zparsor   Zjedi.inference.utilsr   r*   r   Zjedi.inference.helpersr   r#   r   r   r8   rD   rB   r!   r!   r!   r"   Ú<module>   s   #
r