Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/astroid/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/astroid/__pycache__/arguments.cpython-37.opt-1.pyc

B

��\.�@sNddlmZddlmZddlmZddlmZddlmZGdd�d�ZdS)	�)�bases)�context)�
exceptions)�nodes)�utilc@sNeZdZdZddd�Zedd��Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�ZdS)�CallSiteaSClass for understanding arguments passed into a call site

    It needs a call context, which contains the arguments and the
    keyword arguments that were passed into a given call site.
    In order to infer what an argument represents, call
    :meth:`infer_argument` with the corresponding function node
    and the argument name.
    NcCsj|dkri}||_|j}|j}t�|_|�|�|_|�|�|_dd�|jD�|_	dd�|j�
�D�|_dS)NcSsg|]}|tjk	r|�qS�)r�Uninferable)�.0�argrr�B/opt/alt/python37/lib/python3.7/site-packages/astroid/arguments.py�
<listcomp>'sz%CallSite.__init__.<locals>.<listcomp>cSs i|]\}}|tjk	r||�qSr)rr	)r
�key�valuerrr�
<dictcomp>)sz%CallSite.__init__.<locals>.<dictcomp>)�argument_context_map�args�keywords�set�duplicated_keywords�_unpack_args�_unpacked_args�_unpack_keywords�_unpacked_kwargs�positional_arguments�items�keyword_arguments)�self�callcontextrrrrrr�__init__szCallSite.__init__cCst�|j|j�}||�S)z/Get a CallSite object from the given Call node.)�
contextmodZCallContextrr)�clsZ	call_noderrrr�	from_call/szCallSite.from_callcCst|j�t|j�kS)anCheck if in the current CallSite were passed *invalid* arguments

        This can mean multiple things. For instance, if an unpacking
        of an invalid object was passed, then this method will return True.
        Other cases can be when the arguments can't be inferred by astroid,
        for example, by passing objects which aren't known statically.
        )�lenrr)rrrr�has_invalid_arguments5szCallSite.has_invalid_argumentscCst|j�t|j�kS)afCheck if in the current CallSite were passed *invalid* keyword arguments

        For instance, unpacking a dictionary with integer keys is invalid
        (**{1:2}), because the keys must be strings, which will make this
        method to return True. Other cases where this might return True if
        objects which can't be inferred were passed.
        )r#rr)rrrr�has_invalid_keywords?szCallSite.has_invalid_keywordsc	
Cs@i}t��}|j|_�x$|D�]\}}|dk�r0yt|j|d��}Wn"tjk
rftj	||<wYnXt
|tj�s�tj	||<qx�|j
D]�\}}yt|j|d��}Wn"tjk
r�tj	||<w�YnXt
|tj�s�tj	||<q�t
|jt�s�tj	||<q�|j|k�r tj	||j<|j�|j�q�|||j<q�Wq|||<qW|S)N)r)r �InferenceContextr�
extra_context�next�inferr�InferenceErrorrr	�
isinstancer�DictrZConstr�strr�add)	rr�valuesr�namer�inferredZdict_keyZ
dict_valuerrrrIs@





zCallSite._unpack_keywordsc	Cs�g}t��}|j|_x�|D]�}t|tj�r�yt|jj	|d��}Wn$t
jk
rd|�t
j�wYnX|t
jkr~|�t
j�qt|d�s�|�t
j�q|�|j�q|�|�qW|S)N)r�elts)r r&rr'r+rZStarredr(rr)rr*�appendrr	�hasattr�extendr2)rrr/rrr1rrrrqs&


zCallSite._unpack_argsc	s,||jkrtjd||||d��y|j|�|�Stk
rBYnXt|j�t|jj�krv|jj	svtjd||||d��|jdt|jj��}|jt|jj�d�}|j�
|�d}dd�|jjD���fdd	�|j��D�}t|�t|jj�k�r(x4|jjD](}|j
|k�r�|�|j
�}	|�|	��q�W|dk	�r|dk�r�|jd
k�r�|jdk	�r\|j}
n
|j��}
t|
tj��r�|j��}||
��k�r�t|
f�S|jdk�r�t|
tj��s�t�|
�}
t|
f�S|jdk�r�t|
f�S|jd
k�r�|d
8}y|j|�|�Stk
�rYnX|jj|k�r�|���rJtjd|j|j||||d��tj |jj!|jj"|jd�}|�#dd�|��D��t|f�S|jj	|k�r�|�$��r�tjd|j|j%||||d��tj&|jj!|jj"|jd�}
|
�#|�t|
f�Sy|j�'|��|�Stj(k
�rYnXtjd||||d��dS)ainfer a function argument value according to the call context

        Arguments:
            funcnode: The function being called.
            name: The name of the argument whose value is being inferred.
            context: Inference context object
        z:The arguments passed to {func!r}  have duplicate keywords.)�	call_site�funcrrzJToo many positional arguments passed to {func!r} that does not have *args.NrcSsh|]
}|j�qSr)r0)r
rrrr�	<setcomp>�sz*CallSite.infer_argument.<locals>.<setcomp>csi|]\}}|�kr||�qSrr)r
rr)�
kwonlyargsrrr�sz+CallSite.infer_argument.<locals>.<dictcomp>)�method�classmethodr:r;�z�Inference failed to find values for all keyword arguments to {func!r}: {unpacked_kwargs!r} doesn't correspond to {keyword_arguments!r}.)rZunpacked_kwargsr6r7rr)�lineno�
col_offset�parentcSsg|]\}}t�|�|f�qSr)rZ
const_factory)r
rrrrrr
�sz+CallSite.infer_argument.<locals>.<listcomp>z�Inference failed to find values for all positional arguments to {func!r}: {unpacked_args!r} doesn't correspond to {positional_arguments!r}.)rZ
unpacked_argsr6r7rrz.No value found for argument {name} to {func!r}))rrr*rr)�KeyErrorr#rr�varargZfind_argnamer9rr0�popr3�type�	boundnoder?�framer+rZClassDefZscope�	metaclass�iterrZInstance�
IndexError�kwargr%rr,r=r>Zpostinitr$rZTupleZ
default_valueZ	NoDefault)rZfuncnoder0rZ
positionalrAZargindex�kwargsZfunc_argrrDZmethod_scoperIrr)r9r�infer_argument�s�















zCallSite.infer_argument)N)�__name__�
__module__�__qualname__�__doc__rr;r"r$r%rrrKrrrrrs


(rN)Zastroidrrr rrrrrrrr�<module>s