Your IP : 216.73.216.196


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__/inference.cpython-37.pyc

B

��\�z�@s�dZddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddlm
Z
ddlmZdd	lmZdd
l
mZddlmZddlmZe��ZdYd
d�Zeej_eej_eej_eej_eej_eej_dZdd�Ze	jd[dd��Zeej_eej_eej _d\dd�Z!dd�Z"dd�Z#e!ej$_dd�Z%d]dd�Z&e	�e	�'e&��ej(_e&ej)_*e	je	j'd^dd���Z+e+ej,_e	je	j'd_d d!���Z-e-ej._e	je	j'd`d"d#���Z/e/ej0_dad$d%�Z1e	�e	�'e1��ej2_e	�e1�ej3_*e	je	j'dbd&d'���Z4e4ej5_e6�Z7e	jdcd(d)��Z8e	�'e8�ej9_e8ej9_*e	je	j'ddd*d+���Z:e:ej;_d,d-�Z<ded.d/�Z=e	je	j'dfd0d1���Z>e=ej?_=e>ej?_d2d3�Z@d4d5�ZAdgd7d8�ZBdhd9d:�ZCd;d<�ZDd=d>�ZEd?d@�ZFdAdB�ZGdCdD�ZHdEdF�ZIe	jJe	j'didGdH���ZKeIejL_IeKejL_djdIdJ�ZMe	je	j'dkdKdL���ZNeMejO_MeNejO_e	jdldMdN��ZPePejQ_e	je	j'dmdOdP���ZReRej)_eRej3_e	je	j'dndQdR���ZSeSejT_e	jdodSdT��ZUeUejV_dpdUdV�ZWeWejX_YdWdX�ZZdS)qzMthis module contains a set of functions to handle inference on astroid trees
�N)�bases)�context)�
exceptions)�
decorators)�helpers)�manager)�nodes)�
dunder_lookup)�	protocols)�utilccs
|VdS)zRinference's end for node such as Module, ClassDef, FunctionDef,
    Const...

    N�)�selfrrr�B/opt/alt/python37/lib/python3.7/site-packages/astroid/inference.py�	infer_end.srcCsvg}xl|jD]b}t|tj�rdt�|j|�}|s<tj||d��t	|d�sTtj||d��|�
t|��q|�|�qW|S)z-Infer all values based on _BaseContainer.elts)�noder�elts)
r�
isinstancer�Starredr�
safe_infer�valuer�InferenceError�hasattr�extend�_infer_sequence_helper�append)rr�values�eltZstarredrrrr>s
rccsRtdd�|jD��s|Vn2t||�}t|�|j|j|jd�}|�|�|VdS)Ncss|]}t|tj�VqdS)N)rrr)�.0�errr�	<genexpr>Qsz!infer_sequence.<locals>.<genexpr>)�lineno�
col_offset�parent)�anyrr�typer r!r"�postinit)r
rr�new_seqrrr�infer_sequenceOs

r'ccsXtdd�|jD��s|Vn8t||�}t|�|j|j|j�}|�t|����|VdS)Ncss|]\}}t|tj�VqdS)N)rr�
DictUnpack)r�k�_rrrrcszinfer_map.<locals>.<genexpr>)	r#�items�
_infer_mapr$r r!r"r%�list)r
rr+r&rrr�	infer_mapbs
r.cCs.t�|��|���}dd�|D�}t|���S)abDelete nodes that equate to duplicate keys

    Since an astroid node doesn't 'equal' another node with the same value,
    this function uses the as_string method to make sure duplicate keys
    don't get through

    Note that both the key and the value are astroid nodes

    Fixes issue with DictUnpack causing duplicte keys
    in inferred Dict items

    :param dict(nodes.NodeNG, nodes.NodeNG) lhs_dict: Dictionary to 'merge' nodes into
    :param dict(nodes.NodeNG, nodes.NodeNG) rhs_dict: Dictionary with nodes to pull from
    :return dict(nodes.NodeNG, nodes.NodeNG): merged dictionary of nodes
    cSsi|]\}}||f|���qSr)�	as_string)r�keyrrrr�
<dictcomp>~sz,_update_with_replacement.<locals>.<dictcomp>)�	itertools�chainr+�dictr)Zlhs_dictZrhs_dictZ
combined_dictZ
string_maprrr�_update_with_replacementlsr5cCs�i}x�|jD]�\}}t|tj�rft�||�}|s6tj�t|tj�sPtj||d��t	||�}t
||�}qtj||d�}tj||d�}tdd�||fD��r�tj||d��t
|||i�}qW|S)z$Infer all values based on Dict.items)rr)rcss|]}|VqdS)Nr)r�elemrrrr�sz_infer_map.<locals>.<genexpr>)r+rrr(rrrr�Dictr,r5r#)rrr�namerZdouble_starredZunpack_itemsr0rrrr,�s 
r,cCs8|}x|jr"t|jtj�s"|j}qW|r4|jr4|jSdS)a� Search for the first function which encloses the given
    scope. This can be used for looking up in that function's
    scope, in case looking up in a lower scope for a particular
    name fails.

    :param node: A scope node.
    :returns:
        ``None``, if no parent function scope was found,
        otherwise an instance of :class:`astroid.scoped_nodes.Function`,
        which encloses the given node.
    N)r"rr�FunctionDef)r�currentrrr�_higher_function_scope�s

r;cCsn|�|j�\}}|sNt|���}|r4|�|j�\}}|sNtj|j|��|d��t�|�}|j|_t	�
|||�S)z#infer a Name: use name lookup rules)r8�scoper)�lookupr8r;r<rZNameInferenceError�
contextmod�copy_context�
lookupnamer�_infer_stmts)r
r�frame�stmtsZparent_functionr*rrr�
infer_name�s
rDc	cs�t�|�}tj|j|jd�|_d|_|dk	r<t||���|_	xb|j
�|�D]R}|tj
kr`|VqJy"t|d�r�|j||d�EdHWqJtjk
r�wJYqJXqJWt||d�S)z>infer a Call node by trying to guess what the function returns)�args�keywordsN�infer_call_result)�callerr)rr)r>r?�CallContextrErF�callcontext�	boundnode�_populate_context_lookup�cloneZ
extra_context�func�inferr�UninferablerrGrrr4)r
rrJZcalleerrr�
infer_call�s 


rQTc
cs~|j}|dkrtj||d��y(|r6|�|�|��Vn|�|�VWn4tjk
rx}ztj||d�|�Wdd}~XYnXdS)z7infer an Import node: return the imported module/objectN)rr)r@rr�do_import_module�	real_name�AstroidBuildingError)r
r�asnamer8�excrrr�infer_import�srWc
Cs�|j}|dkrtj||d��|r*|�|�}y|��}Wn4tjk
rj}ztj||d�|�Wdd}~XYnXy2t�|�}||_|j|||�	�kd�}t
�||�Stjk
r�}ztj|j
|||d�|�Wdd}~XYnXdS)z:infer a ImportFrom node: return the imported module/objectN)rr)Z
ignore_locals)�target�	attributer)r@rrrSrRrTr>r?�getattr�rootrrA�AttributeInferenceError�message)r
rrUr8�modulerVrC�errorrrr�infer_import_from�s$
"
r`c
cs�x�|j�|�D]�}|tjkr$|Vq|r�|jr�t|tj�r�t|jtj�r�y$t�	t�
|j�t�
|��rj|j}Wntjk
r�YnXy$||_|�
|j|�EdHd|_Wqtjtjfk
r�d|_Yqtk
r�d|_YqXqWt||d�S)zAinfer an Attribute node by using getattr on the associated objectN)rr)�exprrOrrPrKrr�Instancer�
is_subtype�object_typer�_NonDeducibleTypeHierarchy�igetattr�attrnamer\r�AttributeErrorr4)r
r�ownerrrr�infer_attributes.





rjc
Csr|jdkrtj||d��yt�|���|j�|�Stjk
rl}ztj|j||j|d�|�Wdd}~XYnXdS)N)rr)rXrYr)	r@rrrrAr[rZr\r])r
rr_rrr�infer_global@s
rkc	
csPd}�x2|j�|�D�] }|tjkr0tjVdS�x|j�|�D]�}|tjkrZtjVdSt}|jtjkrp|}n$|jtjkr�t	�
|�}|r�|}n|}|tkr�tj||d��y|�
||�}Wn@tjtjtjtfk
r�}ztj||d�|�Wdd}~XYnX||k�s|tjk�rtjVdS|�|�EdHd}q@WqW|�rLt||d�SdS)z�Inference for subscripts

    We're understanding if the index is a Const
    or a slice, passing the result of inference
    to the value's `getitem` method, which should
    handle each supported index type accordingly.
    FN)rrT)rrOrrP�slice�_SUBSCRIPT_SENTINEL�	__class__rrbrZclass_instance_as_indexrr�getitemZAstroidTypeErrorZAstroidIndexErrorr\rhr4)	r
rZ	found_oner�indexZindex_valueZinstance_as_index�assignedrVrrr�infer_subscriptSsF



"rrc#s�|j}|jdkrtj}ntj}y�fdd�|D�}Wntjk
rRtjVdSXx�t	j
|�D]~}tdd�|D��r�tjVq`dd�|D�}tdd�|D��r�tjVq`tj}x,t||�D]\}}||�r�|VPq�W|Vq`Wt
|�d	�S)
z�Infer a boolean operation (and / or / not).

    The function will calculate the boolean operation
    for all pairs generated through inference for each component
    node.
    �orcsg|]}|j�d��qS))r)rO)rr)rrr�
<listcomp>�sz!_infer_boolop.<locals>.<listcomp>Ncss|]}|tjkVqdS)N)rrP)r�itemrrrr�sz _infer_boolop.<locals>.<genexpr>cSsg|]}|���qSr)�
bool_value)rrurrrrt�scss|]}|tjkVqdS)N)rrP)rrurrrr�s)rr)r�op�operator�truth�not_rrrrPr2�productr#�zipr4)r
rr�	predicate�pairZbool_valuesrrvr)rr�
_infer_boolop�s0	

rccs2x,|||�D]}t||�r$tjVq|VqWdS)N)rrrP)r
Zinfer_callablerr_�resultrrr�_filter_operation_errors�s

r�c
cs�x�|j�|�D�]�}y|�|j�VWqtk
r\}zt�||j|�VWdd}~XYqtk
�r�}�z�tj	|j}|dkr�|�
�}|tjk	r�t�
|�VntjV�n:t|tjtjf�s�t�||j|�Vwy�yt�||�}Wn,tjk
�rt�||j|�VwYnX|d}t|j|d��}|tjk�sF|���sHwt�|�}tj|gd�|_|j||d�}t|d�}	|	dk�r�|Vn|	VWnVtjk
�r�}zt�||j|�VWdd}~XYn tjk
�r�tjVYnXWdd}~XYqXqWdS)z3Infer what an UnaryOp should return when evaluated.Nr)r)rE)�operandrOZinfer_unary_oprw�	TypeErrorr�BadUnaryOperationMessagerhr
ZUNARY_OP_METHODrvrPrZ
const_factoryrrrb�ClassDefr	r=rr\�next�callabler>r?rIrJrGr)
r
rr�rV�methrv�methods�inferredZcall_resultsr�rrr�_infer_unaryop�sH"




"r�ccs"t|t|tj�EdHt||d�S)z3Infer what an UnaryOp should return when evaluated.N)rr)r�r�rr�r4)r
rrrr�
infer_unaryopsr�cCst|tj�o|jtkS)z0Check if the given const node is NotImplemented.)rr�Constr�NotImplemented)�constrrr�_is_not_implementedsr�c	CsRt�||�}t�||�}|d}t|j|d��}|tjkr@tj	�|�
|||||�S)z8Invoke binary operation inference on the given instance.r)r)r	r=r>�bind_context_to_noder�rOrrPrrZinfer_binary_op)	�instance�opnoderw�otherr�method_namer��methodr�rrr�_invoke_binop_inferences
r�Fc	Cs"tj|}tjt||||||d�S)z<Get an inference callable for an augmented binary operation.)r�rwr�r�rr�)r
ZAUGMENTED_OP_METHOD�	functools�partialr�)r�r�rwr�r�reverser�rrr�_aug_op*s
r�c	Cs2|rtj|}n
tj|}tjt||||||d�S)z�Get an inference callable for a normal binary operation.

    If *reverse* is True, then the reflected method will be used instead.
    )r�rwr�r�rr�)r
ZREFLECTED_BIN_OP_METHODZ
BIN_OP_METHODr�r�r�)r�r�rwr�rr�r�rrr�_bin_op8s
r�ccs:x4||fD](}|��}tj|gd�|_d|_|Vq
WdS)z�Get contexts for binary operations.

    This will return two inference contexts, the first one
    for x.__op__(y), the other one for y.__rop__(x), where
    only the arguments are inversed.
    )rEN)rMr>rIrJrK)r�left�right�arg�new_contextrrr�_get_binop_contextsLs
	r�cCs|��|��kS)z$Check if type1 is the same as type2.)Zqname)Ztype1Ztype2rrr�
_same_type\sr�c		Cs�|j}t||�r$t|||||�g}nvt�||�rDt|||||�g}nVt�||�rvt|||||dd�t|||||�g}n$t|||||�t|||||dd�g}|S)aVGet the flow for binary operations.

    The rules are a bit messy:

        * if left and right have the same type, then only one
          method will be called, left.__op__(right)
        * if left and right are unrelated typewise, then first
          left.__op__(right) is tried and if this does not exist
          or returns NotImplemented, then right.__rop__(left) is tried.
        * if left is a subtype of right, then only left.__op__(right)
          is tried.
        * if left is a supertype of right, then right.__rop__(left)
          is first tried and then left.__op__(right)
    T)r�)rwr�r�rrc�is_supertype)	r��	left_type�
binary_opnoder��
right_typer�reverse_contextrwr�rrr�_get_binop_flowas
r�c

Cs�|j�d�}|j}t||�r>t|||||�t|||||�g}	n�t�||�rlt|||||�t|||||�g}	nrt�||�r�t|||||�t|||||dd�t|||||�g}	n2t|||||�t|||||�t|||||dd�g}	|	S)a�Get the flow for augmented binary operations.

    The rules are a bit messy:

        * if left and right have the same type, then left.__augop__(right)
          is first tried and then left.__op__(right).
        * if left and right are unrelated typewise, then
          left.__augop__(right) is tried, then left.__op__(right)
          is tried and then right.__rop__(left) is tried.
        * if left is a subtype of right, then left.__augop__(right)
          is tried and then left.__op__(right).
        * if left is a supertype of right, then left.__augop__(right)
          is tried, then right.__rop__(left) and then
          left.__op__(right)
    �=T)r�)rw�stripr�r�r�rrcr�)
r�r�Z
aug_opnoder�r�rr�Zbin_opZaug_opr�rrr�
_get_aug_flow�s 
r�c	cst|||�\}}t�|�}t�|�}||||||||�}x�|D]�}	yt|	��}
WnHtk
rfw>Yq>tjk
r|w>Yq>tjk
r�tj	VdSXt
dd�|
D��r�tj	VdSttt
|
��r�q>tdd�|
D��}|r�|t|
�kr�tj	VdS|
EdHdSq>Wt�||j|�VdS)z�Infer a binary operation between a left operand and a right operand

    This is used by both normal binary operations and augmented binary
    operations, the only difference is the flow factory used.
    Ncss|]}|tjkVqdS)N)rrP)rr�rrrr�sz*_infer_binary_operation.<locals>.<genexpr>css|]}t|�rdVqdS)�N)r�)rr�rrrr�s)r�rrdr-rhrr\rrrPr#�all�mapr��sum�len�BadBinaryOperationMessagerw)r�r�r�r�flow_factoryr�r�r�r�r��resultsZnot_implementedrrr�_infer_binary_operation�s8



r�c
	cs�|j}|j}|pt��}t�|�}t�|�}|j|d�}|j|d�}xtt�||�D]d\}}	tdd�|	|fD��r|t	j
VdSyt||	||t�EdHWqRt
jk
r�t	j
VYqRXqRWdS)z!Binary operation inference logic.)rcss|]}|tjkVqdS)N)rrP)rrrrrr�sz_infer_binop.<locals>.<genexpr>N)r�r�r>�InferenceContextr?rOr2r{r#rrPr�r�rre)
r
rr�r�Zlhs_context�rhs_context�lhs_iter�rhs_iter�lhs�rhsrrr�_infer_binop�s

r�cCst|t|tj�S)N)r�r�rr�)r
rrrr�infer_binop�sr�c	cs�|dkrt��}|��}|jj|d�}|jj|d�}xvt�||�D]f\}}t	dd�||fD��rlt
jVdSyt||||t
d�EdHWqBtjk
r�t
jVYqBXqBWdS)z0Inference logic for augmented binary operations.N)rcss|]}|tjkVqdS)N)rrP)rrrrrrsz#_infer_augassign.<locals>.<genexpr>)r�r�r�rr�)r>r�rMrX�	infer_lhsrrOr2r{r#rrPr�r�rre)r
rr�r�r�r�r�rrr�_infer_augassigns$r�cCst|t|tj�S)N)r�r�rr�)r
rrrr�infer_augassignsr�cCs*|j}|dkrtj||d��t�|||�S)N)rr)r@rrr
Z_arguments_infer_argname)r
rr8rrr�infer_arguments+sr�cCs:|��}t|tj�r|�|�St|j|d��}t�||�S)zWinfer a AssignName/AssignAttr: need to inspect the RHS part of the
    assign node
    )r)	Z	statementrr�	AugAssignrOr-Zassigned_stmtsrrA)r
rZstmtrCrrr�infer_assign6s

r�ccsP|��stjVn:ytj|j|d�EdHWntjk
rJtjVYnXdS)N)r)Zhas_underlying_objectrrP�MANAGERZinfer_ast_from_something�objectrZAstroidError)r
rrrr�infer_empty_nodeHs
r�cCs|j�|�S)N)rrO)r
rrrr�infer_indexWsr�cCsdt�||�}|s|}tj|gd�|_t|jd|d�d�}t|tj�sTt	j
d||d��t|�||��S)N)rE�__getitem__)rz(Could not find __getitem__ for {node!r}.)rr)r>r�rIrJr�rfrrZBoundMethodrrrG)r
rprr�r�rrr�instance_getitem`sr�cCspi}|dkr|Sx.|jD]$}t|tj�r4|||j<q|||<qW|jdk	rP|jng}x|D]}|||j<qZW|S)N)rErrrrrF)�callrZcontext_lookupr�rF�keywordrrrrLus
rL)N)N)N)N)N)N)NT)NT)N)N)N)N)N)N)F)F)N)N)N)N)N)N)N)N)[�__doc__r�r2rx�astroidrrr>rrrrrZastroid.interpreterr	r
rZAstroidManagerr�r�ModuleZ_inferr�r9ZLambdar�ZSlicerZraise_if_nothing_inferredr'ZListZTuple�Setr.r5r,r7r;rDZpath_wrapper�NameZ
AssignNamer�rQZCallrWZImportr`Z
ImportFromrj�	AttributeZ
AssignAttrrkZGlobalr�rmrrZ	SubscriptrZBoolOpr�r�r�ZUnaryOpr�r�r�r�r�r�r�r�r�r�Zyes_if_nothing_inferredr�ZBinOpr�r�r�r��	Argumentsr�r�Z	EmptyNoder�ZIndexr�rbrorLrrrr�<module>s�






$83
6

#-,