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__/bases.cpython-37.opt-1.pyc

B

��\VJ�
@s8dZddlZddlZddlZddlmZddlmZddlmZe�	d�Z
e�	d�ZejZ
e�	d�Ze��Zejd	kr�d
Z
dZndZ
d
Ze
ddhZddddddddddh
Zdd�ZGdd�d�Zd.dd�Zd d!�ZGd"d#�d#e�ZGd$d%�d%e�ZGd&d'�d'e�ZGd(d)�d)e�ZGd*d+�d+e�ZGd,d-�d-e�ZdS)/zXThis module contains base classes and functions for the nodes and some
inference utils.
�N)�context)�
exceptions)�utilzinterpreter.objectmodel�helpers�manager)�r�builtins�__bool__Z__builtin__Z__nonzero__z	.propertyzabc.abstractpropertyZcached_propertyZcachedpropertyZlazypropertyZ
lazy_propertyZreifyZ
lazyattributeZlazy_attributeZLazyPropertyZlazyZcache_readonlycs�t�|���rdSdd�|��D��t�fdd�tD��r>dS|jsHdSx�|jjpTdD]t}t�|�}|dksV|t	j
krxqV|jjdkrVxD|j
D]:}|jjd	kr�q�|�|j�\}}|jtkr�|jd
kr�dSq�WqVWdS)NTcSs$h|]}|tjk	r|�d�d�qS)�.���)r�Uninferable�split)�.0�name�r�>/opt/alt/python37/lib/python3.7/site-packages/astroid/bases.py�	<setcomp>Dsz_is_property.<locals>.<setcomp>c3s|]}|�kVqdS)Nr)rr)�strippedrr�	<genexpr>Isz_is_property.<locals>.<genexpr>Fr�ClassDef�Name�property)�
PROPERTIES�intersectionZdecoratornames�any�POSSIBLE_PROPERTIES�
decoratorsZnodesrZ
safe_inferrr�	__class__�__name__�bases�lookupr�BUILTINS)�methZ	decorator�inferredZ
base_class�module�_r)rr�_is_propertyAs(
r&c@s0eZdZdZdZd	dd�Zdd�Zd
dd�ZdS)�Proxyz�a simple proxy object

    Note:

    Subclasses of this object will need a custom __getattr__
    if new instance attributes are created. See the Const class
    NcCs|dk	r||_dS)N)�_proxied)�selfZproxiedrrr�__init__iszProxy.__init__cCs4|dkrt|jd�S||jkr(|j|St|j|�S)Nr()�getattrr�__dict__r()r)rrrr�__getattr__ms


zProxy.__getattr__ccs
|VdS)Nr)r)rrrr�infertszProxy.infer)N)N)r�
__module__�__qualname__�__doc__r(r*r-r.rrrrr'^s

r'c	cs�d}|dk	r|j}|��}nd}t��}x�|D]�}|tjkrH|Vd}q.|�||�|_y$x|j|d�D]}|Vd}qfWWq.tj	k
r�w.Yq.tj
k
r�tjVd}Yq.Xq.W|s�tj
d|||d��dS)zGReturn an iterator on statements inferred by each statement in *stmts*.FNT)rz.Inference failed for all members of {stmts!r}.)�stmts�framer)Z
lookupnameZclone�
contextmod�InferenceContextrrZ_infer_namer.rZNameInferenceError�InferenceError)r2rr3r#rZstmtrrr�_infer_stmtsxs6


r7cCs�t|j||d�d�}|r�t|d�r�|��s0tjSy@x:|j||d�D](}|tjkrT|St|j|d��}|��SWWnt	j
k
r�YnXtjS)N)r�infer_call_result)�next�igetattr�hasattr�callablerrr8r.�
bool_valuerr6)�instanceZmethod_namerr"�valuer#rrr�_infer_method_result_truth�s
r@c@sDeZdZdZdZdd�Zddd�Zddd	�Zdd
d�Zddd
�Z	dS)�BaseInstancezNAn instance base class, which provides lookup methods for potential instances.NcCsdS)NzInstance ofr)r)rrr�display_type�szBaseInstance.display_typeTc
Cs�y|j�||�}Wnjtjk
r|}zJ|jrD||jkrD|j�|�gS|rZ|jj||dd�Stj|||d�|�Wdd}~XYnX|r�y||jj||dd�Stjk
r�YnX|S)NF)�
class_context)�targetZ	attributer)r(Z
instance_attrr�AttributeInferenceError�special_attributesr r+)r)rr�lookupclass�values�excrrrr+�s"
zBaseInstance.getattrc
cs�|st��}yD|�|j|f�r"dS|j||dd�}t|�||�||d�EdHWn�tjk
r�}z�yH|jj	j
dkr�tjft|��|�|jj
||dd�}|�||�EdHWn6tjk
r�}ztjft|��|�Wdd}~XYnXWdd}~XYnXdS)zinferred getattrNF)rG)r3r)rC)r4r5�pushr(r+r7�
_wrap_attrrrErrr6�varsr:)r)rrZget_attr�error�attrsrrrr:�s zBaseInstance.igetattrccs�x�|D]�}t|t�r>t|�r0|�||�EdHq�t||�Vqt|d�r�|jdkr�|����|j	kr�|j
j
r�|j
j
djdkr�t||�Vq|Vq|VqWdS)z7wrap bound methods of attrs in a InstanceMethod proxiesNrz<lambda>rr))�
isinstance�
UnboundMethodr&r8�BoundMethodr;rZ	statementZscoper(�args)r)rNr�attrrrrrK�s

zBaseInstance._wrap_attrccstt�||�}d}xJ|j�d|�D]8}|tjks |��s8q x|�||�D]}d}|VqFWq W|sptj	|||d��dS)z4infer what a class instance is returning when calledF�__call__T)�node�callerrN)
r4�bind_context_to_noder(r:rrr<r8rr6)r)rVrr#rU�resrrrr8�szBaseInstance.infer_call_result)NT)N)N)N)
rr/r0r1rFrBr+r:rKr8rrrrrA�s


rAc@sXeZdZdZe�dd��Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zddd�Z
dS)�Instancez-A special node representing a class instance.cCst��S)N)�objectmodelZ
InstanceModelrrrr�<lambda>�zInstance.<lambda>cCsd|j��j|jjt|�fS)Nz<Instance of %s.%s at 0x%s>)r(�rootr�id)r)rrr�__repr__s
zInstance.__repr__cCsd|j��j|jjfS)NzInstance of %s.%s)r(r]r)r)rrr�__str__szInstance.__str__cCs0y|jjddd�dStjk
r*dSXdS)NrTF)rCT)r(r+rrE)r)rrrr<s
zInstance.callablecCs
|j��S)N)r(�qname)r)rrr�pytype$szInstance.pytypecCsdS)NzInstance ofr)r)rrrrB'szInstance.display_typecCs|t��}tjgd�|_||_yt|t|�}WnJtjtj	fk
rvyt|d|�}Wntj	tjfk
rpdSXYnX|S)aVInfer the truth value for an Instance

        The truth value of an instance is determined by these conditions:

           * if it implements __bool__ on Python 3 or __nonzero__
             on Python 2, then its bool value will be determined by
             calling this special method and checking its result.
           * when this method is not defined, __len__() is called, if it
             is defined, and the object is considered true if its result is
             nonzero. If a class defines neither __len__() nor __bool__(),
             all its instances are considered true.
        )rR�__len__T)
r4r5ZCallContextZcallcontextZ	boundnoder@�BOOL_SPECIAL_METHODrr6rE)r)r�resultrrrr=*s
zInstance.bool_valueNcCsdS)Nr)r)�indexrrrr�getitemFszInstance.getitem)N)rr/r0r1r�lazy_descriptorrFr_r`r<rbrBr=rgrrrrrY
srYc@sZeZdZdZe�dd��Zdd�Zdd�Zdd	�Z	ddd�Z
dd
d�Zdd�Zdd�Z
d
S)rPz=a special node representing a method not bound to an instancecCst��S)N)rZZUnboundMethodModelrrrrr[Nr\zUnboundMethod.<lambda>cCs,|jj��}d|jj|jj|��t|�fS)Nz<%s %s of %s at 0x%s)r(�parentr3rrrrar^)r)r3rrrr_PszUnboundMethod.__repr__cCsdS)Nrr)r)rrr�implicit_parametersYsz!UnboundMethod.implicit_parameterscCsdS)NFr)r)rrr�is_bound\szUnboundMethod.is_boundNcCs&||jkr|j�|�gS|j�||�S)N)rFr r(r+)r)rrrrrr+_s
zUnboundMethod.getattrcCs*||jkrt|j�|�f�S|j�||�S)N)rF�iterr r(r:)r)rrrrrr:ds
zUnboundMethod.igetattrcCsp|jjdkrb|jj����dtkrb|jrP|j�|jd�}|jdj	|d�}ng}dd�|D�S|j�
||�S)a�
        The boundnode of the regular context with a function called
        on ``object.__new__`` will be of type ``object``,
        which is incorrect for the argument in general.
        If no context is given the ``object.__new__`` call argument will
        correctly inferred except when inside a call that requires
        the additional context (such as a classmethod) of the boundnode
        to determine which class the method was called from
        �__new__z	%s.objectr)rcss$|]}|tjk	rt|�n|VqdS)N)rrrY)r�xrrrrsz2UnboundMethod.infer_call_result.<locals>.<genexpr>)r(rrir3rar!rRZ
extra_context�getr.r8)r)rVrZnode_contextr.rrrr8iszUnboundMethod.infer_call_resultcCsdS)NTr)r)rrrr=�szUnboundMethod.bool_value)N)N)rr/r0r1rrhrFr_rjrkr+r:r8r=rrrrrPJs	

rPcsXeZdZdZe�dd��Zdd�Zdd�Zdd	�Z	d
d�Z
d�fd
d�	Zdd�Z�Z
S)rQz9a special node representing a method bound to an instancecCst��S)N)rZZBoundMethodModelrrrrr[�r\zBoundMethod.<lambda>cCst�||�||_dS)N)rPr*�bound)r)�proxyrprrrr*�szBoundMethod.__init__cCsdS)N�r)r)rrrrj�szBoundMethod.implicit_parameterscCsdS)NTr)r)rrrrk�szBoundMethod.is_boundcs�ddlm}t|jdj�d��}|jjdkr2dS|�dt�sDdSt|jdj�d��}|jjdkrjdSt	|j
t�szdSt|jd	j�d��}|jjd
kr�dS�fdd�|jD�}t
d
d�|D��r�dSt|jdj�d��}|jjdkr�dSt�t�}	x`|jD]V\}
}t|
j�d��}
t|j�d��}|
jjdk�rt	|
j
t��r|	|
j
�|��qW|j|j
|j|j|d�}|��}
|j|j|
ggd|gd�|	|_|S)z�Try to infer what type.__new__(mcs, name, bases, attrs) returns.

        In order for such call to be valid, the metaclass needs to be
        a subtype of ``type``, the name needs to be a string, the bases
        needs to be a tuple of classes
        r)�node_classes)rrNz%s.typerrZConst�ZTuplecsg|]}t|j�d���qS))r)r9r.)rZelt)rrr�
<listcomp>�sz4BoundMethod._infer_type_new_call.<locals>.<listcomp>css|]}|jjdkVqdS)rN)rr)r�baserrrr�sz3BoundMethod._infer_type_new_call.<locals>.<genexpr>rZDict)r�lineno�
col_offsetriT)rZbodyrZnewstyle�	metaclass�keywords)�astroidrsr9rRr.rrZ
is_subtype_ofr!rOr?�strZeltsr�collections�defaultdict�list�items�appendrwrxZPassZpostinit�locals)r)rVrrsZmcsrrZinferred_basesrNZ
cls_locals�keyr?�cls�emptyr)rr�_infer_type_new_call�sR
z BoundMethod._infer_type_new_callNcslt�||j�}|jjjdkrZ|jjdkrZ|jdkrZt|j�dkrZ|�||�}|rZt	|f�St
t|��||�S)Nr�typerm�)
r4rWrprrr�lenrRr�rl�superrQr8)r)rVrZnew_cls)rrrr8�s

zBoundMethod.infer_call_resultcCsdS)NTr)r)rrrr=�szBoundMethod.bool_value)N)rr/r0r1rrhrFr*rjrkr�r8r=�
__classcell__rr)rrrQ�sErQc@sXeZdZdZe�dd��Zddd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dS)�	Generatorzea special node representing a generator.

    Proxied class is set once for all in raw_building.
    cCst��S)N)rZZGeneratorModelrrrrr[�r\zGenerator.<lambda>NcCs
||_dS)N)ri)r)rirrrr*�szGenerator.__init__cCsdS)NFr)r)rrrr<�szGenerator.callablecCsdtS)Nz%s.generator)r!)r)rrrrb�szGenerator.pytypecCsdS)Nr�r)r)rrrrBszGenerator.display_typecCsdS)NTr)r)rrrr=szGenerator.bool_valuecCsd|jj|jt|�fS)Nz<Generator(%s) l.%s at 0x%s>)r(rrwr^)r)rrrr_szGenerator.__repr__cCsd|jjS)Nz
Generator(%s))r(r)r)rrrr`szGenerator.__str__)N)rr/r0r1rrhrFr*r<rbrBr=r_r`rrrrr��s
r�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�AsyncGeneratorz,Special node representing an async generatorcCsdtS)Nz%s.async_generator)r!)r)rrrrbszAsyncGenerator.pytypecCsdS)Nr�r)r)rrrrBszAsyncGenerator.display_typecCsd|jj|jt|�fS)Nz!<AsyncGenerator(%s) l.%s at 0x%s>)r(rrwr^)r)rrrr_szAsyncGenerator.__repr__cCsd|jjS)NzAsyncGenerator(%s))r(r)r)rrrr`"szAsyncGenerator.__str__N)rr/r0r1rbrBr_r`rrrrr�s
r�)N)r1rr}�sysr{rr4rrZlazy_importrZrrr!rZAstroidManagerZMANAGER�version_infordrrr&r'r7r@rArYrPrQr�r�rrrr�<module>sJ





"`=<h$