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.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__�__builtin__�__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/r0rrrrr)^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
lookupname�clone�
contextmod�InferenceContextrrZ_infer_namer0rZNameInferenceError�InferenceError)r4rr5r%rZstmtrrr�_infer_stmtsxs6


r:cCs�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�callablerrr;r0�
bool_valuerr9)�instance�method_namerr$�valuer%rrr�_infer_method_result_truth�s
rDc@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)�target�	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)rL)r5r)rG)r7r8�pushr*r-r:�
_wrap_attrrrJrr r9�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(r;�BoundMethodr>rZ	statementZscoper*�args)r+rSr�attrrrrrP�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)
r7�bind_context_to_noder*r=rrr?r;rr9)r+r[rr%rZ�resrrrr;�szBaseInstance.infer_call_result)NT)N)N)N)
r r1r2r3rKrFr-r=rPr;rrrrrE�s


rEc@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*rbr)r+rrr�__str__szInstance.__str__cCs0y|jjddd�dStjk
r*dSXdS)NrYF)rGT)r*r-rrJ)r+rrrr?s
zInstance.callablecCs
|j��S)N)r*�qname)r+rrr�pytype$szInstance.pytypecCsdS)NzInstance ofr)r+rrrrF'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.
        )rW�__len__T)
r7r8ZCallContextZcallcontextZ	boundnoderD�BOOL_SPECIAL_METHODrr9rJ)r+r�resultrrrr@*s
zInstance.bool_valueNcCsdS)Nr)r+�indexrrrr�getitemFszInstance.getitem)N)r r1r2r3r�lazy_descriptorrKrdrer?rgrFr@rlrrrrr^
sr^c@sZeZdZdZe�dd��Zdd�Zdd�Zdd	�Z	ddd�Z
dd
d�Zdd�Zdd�Z
d
S)rUz=a special node representing a method not bound to an instancecCst��S)N)r_ZUnboundMethodModelrrrrr`NrazUnboundMethod.<lambda>cCs,|jj��}d|jj|jj|��t|�fS)Nz<%s %s of %s at 0x%s)r*�parentr5rr rrfrc)r+r5rrrrdPs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)rKr"r*r-)r+rrrrrr-_s
zUnboundMethod.getattrcCs*||jkrt|j�|�f�S|j�||�S)N)rK�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)rrr^)r�xrrrrsz2UnboundMethod.infer_call_result.<locals>.<genexpr>)r*rrnr5rfr#rWZ
extra_context�getr0r;)r+r[rZnode_contextr0rrrr;iszUnboundMethod.infer_call_resultcCsdS)NTr)r+rrrr@�szUnboundMethod.bool_value)N)N)r r1r2r3rrmrKrdrorpr-r=r;r@rrrrrUJs	

rUcsXeZdZdZe�dd��Zdd�Zdd�Zdd	�Z	d
d�Z
d�fd
d�	Zdd�Z�Z
S)rVz9a special node representing a method bound to an instancecCst��S)N)r_ZBoundMethodModelrrrrr`�razBoundMethod.<lambda>cCst�||�||_dS)N)rUr,�bound)r+�proxyrurrrr,�szBoundMethod.__init__cCsdS)N�r)r+rrrro�szBoundMethod.implicit_parameterscCsdS)NTr)r+rrrrp�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.typerwZConst�ZTuplecsg|]}t|j�d���qS))r)r<r0)r�elt)rrr�
<listcomp>�sz4BoundMethod._infer_type_new_call.<locals>.<listcomp>css|]}|jjdkVqdS)rN)rr )r�baserrrr�sz3BoundMethod._infer_type_new_call.<locals>.<genexpr>r�Dict)r�lineno�
col_offsetrnT)r!�bodyrZnewstyle�	metaclass�keywords)�astroidrxr<rWr0rr Z
is_subtype_ofr#rTrC�strZeltsr�collections�defaultdict�list�items�appendr~rZPassZpostinit�locals)r+r[rrxZmcsrr!Zinferred_basesrSZ
cls_locals�keyrC�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�typerr�)
r7r\rurr r�lenrWr�rq�superrVr;)r+r[rZnew_cls)rrrr;�s

zBoundMethod.infer_call_resultcCsdS)NTr)r+rrrr@�szBoundMethod.bool_value)N)r r1r2r3rrmrKr,rorpr�r;r@�
__classcell__rr)rrrV�sErVc@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)r_ZGeneratorModelrrrrr`�razGenerator.<lambda>NcCs
||_dS)N)rn)r+rnrrrr,�szGenerator.__init__cCsdS)NFr)r+rrrr?�szGenerator.callablecCsdtS)Nz%s.generator)r#)r+rrrrg�szGenerator.pytypecCsdS)Nr�r)r+rrrrFszGenerator.display_typecCsdS)NTr)r+rrrr@szGenerator.bool_valuecCsd|jj|jt|�fS)Nz<Generator(%s) l.%s at 0x%s>)r*rr~rc)r+rrrrdszGenerator.__repr__cCsd|jjS)Nz
Generator(%s))r*r)r+rrrreszGenerator.__str__)N)r r1r2r3rrmrKr,r?rgrFr@rdrerrrrr��s
r�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�AsyncGeneratorz,Special node representing an async generatorcCsdtS)Nz%s.async_generator)r#)r+rrrrgszAsyncGenerator.pytypecCsdS)Nr�r)r+rrrrFszAsyncGenerator.display_typecCsd|jj|jt|�fS)Nz!<AsyncGenerator(%s) l.%s at 0x%s>)r*rr~rc)r+rrrrdszAsyncGenerator.__repr__cCsd|jjS)NzAsyncGenerator(%s))r*r)r+rrrre"szAsyncGenerator.__str__N)r r1r2r3rgrFrdrerrrrr�s
r�)N)r3rr��sysr�rr7rrZlazy_importr_rr r#rZAstroidManagerZMANAGER�version_inforirrr(r)r:rDrEr^rUrVr�r�rrrr�<module>sJ





"`=<h$