B
    S\                @   s  d Z ddlZddlZddlZddl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l
mZ dd	l
mZ dd
l
mZ ddl
mZ ddl
mZ ejZe ZejdddZdddZe ZdddZdddZdddZdd e dgdgdgdgdgdgdgd gd!gd"d#gd$d%gd&d'd(d)d*gd+gd,gd-ggD Z!G d.d/ d/Z"G d0d1 d1e"Z#G d2d3 d3ej$e"ej%ej&d4Z'G d5d6 d6Z(G d7d8 d8ej)e(ej$e"Z*G d9d: d:ej)e(ej$e"Z+G d;d< d<ej)e(e"Z,G d=d> d>ej-e"Z.dd@dAZ/ddBdCZ0G dDdE dEej$e"Z1G dFdG dGe#Z2G dHdI dIej-e#Z3G dJdK dKej-e#Z4G dLdM dMej-e#Z5G dNdO dOe"Z6G dPdQ dQe"Z7G dRdS dSe"Z8G dTdU dUej)e#Z9G dVdW dWe"Z:G dXd de"Z;G dYdZ dZe"Z<G d[d\ d\ej)e"ej%Z=G d]d^ d^ej)e#Z>G d_d` d`e"Z?G dadb dbej$e"Z@G dcdd ddej-e#ZAG dedf dfe"ej%ZBG dgdh dhe#ZCG didj djej)e"ZDG dkdl dlej)e"ZEG dmdn dnejFej-e#ZGG dodp dpe#ZHG dqdr dre"ZIG dsdt dtejFejJej-e#ZKG dudv dveKZLG dwd- d-e"ZMG dxdy dyej)ejNe#ZOG dzd{ d{e"ZPG d|d} d}ej)e#ZQG d~d dejFejJe#ZRG dd de"ZSG dd dej)ejNe#ZTG dd de"ZUG dd de"ZVG dd de'ZWG dd dej)e#ZXG dd dej)e#ZYG dd de#ZZG dd de#Z[G dd de#Z\G dd de'Z]G dd de"Z^G dd dej$e"Z_G dd de"Z`G dd dejFejJe#ZaG dd dejFejJe#ZbG dd de'ZcG dd+ d+e"ZdG dd dejFejJe#ZeG dd dejFejJej-e#ZfG dd defZgG dd de"ZhG dd dehZiG dd dej)e"ZjG dd de"ZkG dd de"ZlG dd dej-e"ZmeneWeoecepeBeqe]erde=erese=iZtdd Zueu  dd Zvdd ZweWeveceveBewe]eve=dd iZxdd Zydd ZzdS )z<Module for some node classes. More nodes in scoped_nodes.py
    N)	lru_cache)singledispatch)	as_string)bases)context)
decorators)
exceptions)manager)mixins)utilc             c   s   t | ttfrLx0| jD ]&}|tjkr,|V  qt||E dH  qW t| |dS t| 	|}|| krt|V  t| |dS x4| 	|D ]&}|tjkr|V  qt||E dH  qW t| |dS )zrecursively generate nodes inferred by the given statement.
    If the inferred value is a list or a tuple, recurse on the elements
    N)noder   )

isinstanceListTupleeltsr   Uninferableunpack_inferdictnextinfer)stmtr   eltinferred r   3lib/python3.7/site-packages/astroid/node_classes.pyr   3   s     

r   c             C   sl  i }i }| j }| }x"|r4d||< |||< |}|j }qW |j }|}x$|rf||krZt|tr|dkr||d ||| d k	rdS nt|trV||\}}||| \}	}
|
|k	r6|dko|	dko||}|dko|	dko|| |}|dko
|	dk}|dko|	dk}t||||frVdS n |dkrV|	dkrV||| k	S dS |}|j }qDW dS )a  return true if the two given statements are mutually exclusive

    `exceptions` may be a list of exception names. If specified, discard If
    branches and check one of the statement is in an exception handler catching
    one of the given exceptions.

    algorithm :
     1) index stmt1's parents
     2) climb among stmt2's parents until we find a common parent
     3) if the common parent is a If or TryExcept statement, look if nodes are
        in exclusive branches
       NThandlersbodyorelseF)parentr   Iflocate_child	TryExceptcatchany)Zstmt1Zstmt2r   Zstmt1_parentsZchildrenr   ZpreviousZc2attrZc2nodeZc1attrZc1nodeZ first_in_body_caught_by_handlersZ!second_in_body_caught_by_handlersZfirst_in_else_other_in_handlersZ second_in_else_other_in_handlersr   r   r   are_exclusiveN   sR    






r%   c             C   s   t | tr&t | jttdfr| jS n\| dkr2dS yt| j|d}W n tjk
r\   Y n&X t |trt |jttdfr|jS t	S )z'Get the value of the given slice index.N)r   )
r   Constvalueinttyper   r   r   InferenceError_SLICE_SENTINEL)indexr   r   r   r   r   _slice_value   s    

r-   c             C   s`   t | j|}t | j|}t | j|}tdd |||fD rHt|||S tjd| | j|dd S )Nc             s   s   | ]}|t k	V  qd S )N)r+   ).0elemr   r   r   	<genexpr>   s    z_infer_slice.<locals>.<genexpr>z'Could not infer slice used in subscript)messager   r,   r   )	r-   lowerupperstepallslicer   AstroidTypeErrorr   )r   r   r2   r3   r4   r   r   r   _infer_slice   s    r8   c          
   C   s   yLt |tr6t||d}|  }|| |_| j|_|S t |trJ||j S W nj tk
r } zt	j
d| ||d|W dd}~X Y n6 tk
r } zt	jd| ||d|W dd}~X Y nX t	d| dS )zHGet a slice or an item, using the given *index*, for the given sequence.)r   zIndex {index!s} out of range)r1   r   r,   r   NzType error {error!r}z#Could not use %s as subscript index)r   Slicer8   	__class__r   r   r&   r'   
IndexErrorr   AstroidIndexError	TypeErrorr7   )instancer   r,   r   Zindex_sliceZnew_clsexcr   r   r   _container_getitem   s*    


r@   c             C   s    i | ]\}}|D ]
}||qqS r   r   )r.   Z
precedenceopsopr   r   r   
<dictcomp>   s   rC   ZLambdaIfExporandnotCompare|^&z<<z>>+-*@/z//%UnaryOpz**Awaitc               @   s  e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdXddZdYddZd	d
 Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Z e!j"d)d* Z#e!j"d+d, Z$d-d. Z%d/d0 Z&d1d2 Z'dZd3d4Z(e!j)d5d6 Z*d7d8 Z+d9d: Z,d;d< Z-d=d> Z.d[d?d@Z/dAdB Z0dCdD Z1dEdF Z2dGdH Z3dIdJ Z4dKdL Z5d\dPdQZ6dRdS Z7dTdU Z8dVdW Z9dS )]NodeNGzm A node of the new Abstract Syntax Tree (AST).

    This is the base class for all Astroid node classes.
    FNr   c             C   s   || _ || _|| _dS )aa  
        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)lineno
col_offsetr   )selfrU   rV   r   r   r   r   __init__9  s    zNodeNG.__init__c             K   s   |dk	r|j | |}| jdk	rHy| j| |f|S  tjk
rF   Y nX |sZ| j|f|S | |j|j|jf}||j	krt
|j	| S ||| j|f|}t|tjS )aV  Get a generator of the inferred values.

        This is the main entry point to the inference system.

        .. seealso:: :ref:`inference`

        If the instance has some explicit inference function set, it will be
        called instead of the default interface.

        :returns: The inferred values.
        :rtype: iterable
        N)Zextra_contextget_explicit_inferencer   ZUseInferenceDefault_inferZ
lookupnameZcallcontextZ	boundnoder   iterZcache_generatorr   Zlimit_inferenceMANAGERZmax_inferable_values)rW   r   kwargskeygenr   r   r   r   I  s    

zNodeNG.inferc                s6   ddh}t  fdd|D r2t dt ddS dS )zGet a name for nice representation.

        This is either :attr:`name`, :attr:`attrname`, or the empty string.

        :returns: The nice name.
        :rtype: str
        nameattrnamec             3   s   | ]}| j kV  qd S )N)_astroid_fields)r.   ra   )rW   r   r   r0   s  s    z$NodeNG._repr_name.<locals>.<genexpr> )r5   getattr)rW   namesr   )rW   r   
_repr_namej  s    zNodeNG._repr_namec             C   s   |   }t| j}|r0d}t|t| d }nd}t|d }g }x| j| j D ]~}t| |}dt| | }tj|d|d	d}	|	d g}
x&|	dd  D ]}|

d	| |  qW |
d
|d|
f  qRW |||dd	|  |d S )Nz%(cname)s.%(rname)s(%(fields)s)   z%(cname)s(%(fields)s)r   P   )indentwidthTr    z%s=%srd   z,
)cnamernamefields)rg   r)   __name__len_other_fieldsrc   re   pprintpformat
splitlinesappendjoin)rW   rn   rm   stringZ	alignmentresultfieldr'   rk   linesinnerliner   r   r   __str__w  s(    


zNodeNG.__str__c             C   s4   |   }|rd}nd}|t| j|| jt| d S )Nz.<%(cname)s.%(rname)s l.%(lineno)s at 0x%(id)x>z$<%(cname)s l.%(lineno)s at 0x%(id)x>)rm   rn   rU   id)rg   r)   rp   
fromlinenor   )rW   rn   rx   r   r   r   __repr__  s    zNodeNG.__repr__c             C   s   t |d| jj  }|| S )z(Visit this node using the given visitor.Zvisit_)re   r:   rp   r2   )rW   Zvisitorfuncr   r   r   accept  s    zNodeNG.acceptc             c   sH   xB| j D ]8}t| |}|dkr qt|ttfr:|E dH  q|V  qW dS )zoGet the child nodes below this node.

        :returns: The children.
        :rtype: iterable(NodeNG)
        N)rc   re   r   listtuple)rW   rz   attrr   r   r   get_children  s    
zNodeNG.get_childrenc             C   sF   x@| j ddd D ],}t| |}|s&qt|ttfr<|d S |S W dS )zAn optimized version of list(get_children())[-1]

        :returns: The last child, or None if no children exist.
        :rtype: NodeNG or None
        N)rc   re   r   r   r   )rW   rz   r   r   r   r   
last_child  s    
zNodeNG.last_childc             C   s*   |j }x|dk	r$| |krdS |j }qW dS )a  Check if this node is the parent of the given node.

        :param node: The node to check if it is the child.
        :type node: NodeNG

        :returns: True if this node is the parent of the given node,
            False otherwise.
        :rtype: bool
        NTF)r   )rW   r   r   r   r   r   	parent_of  s    


zNodeNG.parent_ofc             C   s   | j r
| S | j S )zThe first parent node, including self, marked as statement node.

        :returns: The first parent statement.
        :rtype: NodeNG
        )is_statementr   	statement)rW   r   r   r   r     s    zNodeNG.statementc             C   s
   | j  S )zThe first parent frame node.

        A frame node is a :class:`Module`, :class:`FunctionDef`,
        or :class:`ClassDef`.

        :returns: The first parent frame node.
        :rtype: Module or FunctionDef or ClassDef
        )r   frame)rW   r   r   r   r     s    	zNodeNG.framec             C   s
   | j  S )zThe first parent node defining a new scope.

        :returns: The first parent scope node.
        :rtype: Module or FunctionDef or ClassDef or Lambda or GenExpr
        )r   scope)rW   r   r   r   r     s    zNodeNG.scopec             C   s   | j r| j  S | S )zjReturn the root node of the syntax tree.

        :returns: The root node.
        :rtype: Module
        )r   root)rW   r   r   r   r     s    
zNodeNG.rootc             C   sd   x@| j D ]6}t| |}||kr$|gS t|ttfr||kr|S qW d}t|t|t| f dS )a_  Search for the sequence that contains this child.

        :param child: The child node to search sequences for.
        :type child: NodeNG

        :returns: The sequence containing the given child node.
        :rtype: iterable(NodeNG)

        :raises AstroidError: If no sequence could be found that contains
            the given child.
        z"Could not find %s in %s's childrenN)rc   re   r   r   r   r   AstroidErrorrepr)rW   childrz   node_or_sequencemsgr   r   r   child_sequence  s    
zNodeNG.child_sequencec             C   sj   xF| j D ]<}t| |}||kr&||fS t|ttfr||kr||fS qW d}t|t|t| f dS )a  Find the field of this node that contains the given child.

        :param child: The child node to search fields for.
        :type child: NodeNG

        :returns: A tuple of the name of the field that contains the child,
            and the sequence or node that contains the child node.
        :rtype: tuple(str, iterable(NodeNG) or NodeNG)

        :raises AstroidError: If no field could be found that contains
            the given child.
        z"Could not find %s in %s's childrenN)rc   re   r   r   r   r   r   r   )rW   r   rz   r   r   r   r   r   r!     s    
zNodeNG.locate_childc             C   s
   | j  S )z|The next sibling statement node.

        :returns: The next sibling statement node.
        :rtype: NodeNG or None
        )r   next_sibling)rW   r   r   r   r   1  s    zNodeNG.next_siblingc             C   s
   | j  S )zThe previous sibling statement.

        :returns: The previous sibling statement node.
        :rtype: NodeNG or None
        )r   previous_sibling)rW   r   r   r   r   9  s    zNodeNG.previous_siblingc             C   sj   |   }| j}d}xN|D ]F}|  |ks8td| |f |j}|j|krJP ||d kr||f}qW |d S )a  Get the node closest to this one from the given list of nodes.

        :param nodes: The list of nodes to search. All of these nodes must
            belong to the same module as this one. The list should be
            sorted by the line number of the nodes, smallest first.
        :type nodes: iterable(NodeNG)

        :returns: The node closest to this one in the source code,
            or None if one could not be found.
        :rtype: NodeNG or None
        )Nr   z,nodes %s and %s are not from the same moduler   r   )r   r   AssertionError)rW   nodesZmyrootmylinenonearestr   rU   r   r   r   r   A  s    

zNodeNG.nearestc             C   s   | j dkr|  S | j S )zaThe first line that this node appears on in the source code.

        :type: int or None
        N)rU   _fixed_source_line)rW   r   r   r   r   _  s    
zNodeNG.fromlinenoc             C   s(   | j sd}n|  }|dkr"| jS |jS )z`The last line that this node appears on in the source code.

        :type: int or None
        N)rc   r   r   tolineno)rW   Z	lastchildr   r   r   r   j  s    zNodeNG.tolinenoc             C   sl   | j }| }y$x|dkr*t| }|j }qW W n8 tk
rf   | j}x|r`|dkr`|j }|j}qFW Y nX |S )a  Attempt to find the line that this node appears on.

        We need this method since not all nodes have :attr:`lineno` set.

        :returns: The line number of this node,
            or None if this could not be determined.
        :rtype: int or None
        N)rU   r   r   StopIterationr   )rW   r}   Z_noder   r   r   r   z  s    	
zNodeNG._fixed_source_linec             C   s
   || j fS )a@  Get a range from the given line number to where this node ends.

        :param lineno: The line number to start the range at.
        :type lineno: int

        :returns: The range of line numbers that this node belongs to,
            starting at the given line number.
        :rtype: tuple(int, int or None)
        )r   )rW   rU   r   r   r   block_range  s    
zNodeNG.block_rangec             C   s   | j || dS )aW  Define that the given name is declared in the given statement node.

        This definition is stored on the parent scope node.

        .. seealso:: :meth:`scope`

        :param name: The name that is being defined.
        :type name: str

        :param stmt: The statement that defines the given name.
        :type stmt: NodeNG
        N)r   	set_local)rW   ra   r   r   r   r   r     s    zNodeNG.set_localc             c   st   t | |r| V  |dkr@x"|  D ]}|||E dH  q"W dS x.|  D ]"}t ||rZqJ|||E dH  qJW dS )a  Get the nodes (including this one or below) of the given type.

        :param klass: The type of node to search for.
        :type klass: builtins.type

        :param skip_klass: A type of node to ignore. This is useful to ignore
            subclasses of :attr:`klass`.
        :type skip_klass: builtins.type

        :returns: The node of the given type.
        :rtype: iterable(NodeNG)
        N)r   r   nodes_of_class)rW   klassZ
skip_klass
child_noder   r   r   r     s    

zNodeNG.nodes_of_classc             C   s   g S )Nr   )rW   r   r   r   _get_assign_nodes  s    zNodeNG._get_assign_nodesc             c   s$   x|   D ]}| E d H  q
W d S )N)r   _get_name_nodes)rW   r   r   r   r   r     s    zNodeNG._get_name_nodesc             c   s   dE d H  d S )Nr   r   )rW   r   r   r    _get_return_nodes_skip_functions  s    z'NodeNG._get_return_nodes_skip_functionsc             c   s   dE d H  d S )Nr   r   )rW   r   r   r   _get_yield_nodes_skip_lambdas  s    z$NodeNG._get_yield_nodes_skip_lambdasc             C   s   d S )Nr   )rW   r   ra   r   r   r   _infer_name  s    zNodeNG._infer_namec             C   s   t jd| |ddS )z3we don't know how to resolve a statement by defaultz#No inference function for {node!r}.)r   r   N)r   r*   )rW   r   r   r   r   r[     s    zNodeNG._inferc             C   s   t |  S )zGet a list of the inferred values.

        .. seealso:: :ref:`inference`

        :returns: The inferred values.
        :rtype: list
        )r   r   )rW   r   r   r   r     s    zNodeNG.inferredc             C   s   | S )zInstantiate an instance of the defined class.

        .. note::

            On anything other than a :class:`ClassDef` this will return self.

        :returns: An instance of the defined class.
        :rtype: object
        r   )rW   r   r   r   instantiate_class  s    
zNodeNG.instantiate_classc             C   s   dS )zCheck if this node inherits from the given type.

        :param node: The node defining the base to look for.
            Usually this is a :class:`Name` node.
        :type node: NodeNG
        Fr   )rW   r   r   r   r   has_base  s    zNodeNG.has_basec             C   s   dS )zWhether this node defines something that is callable.

        :returns: True if this defines something that is callable,
            False otherwise.
        :rtype: bool
        Fr   )rW   r   r   r   callable  s    zNodeNG.callablec             C   s   dS )NFr   )rW   r'   r   r   r   eq  s    z	NodeNG.eqc             C   s
   t | S )zoGet the source code that this node represents.

        :returns: The source code.
        :rtype: str
        )r   Zto_code)rW   r   r   r   r   
  s    zNodeNG.as_string   r   ri   c       
         st   t d	fdd	  t td
 fdd	} td fdd	}g }	 | |	t  d|	S )a  Get a string representation of the AST from this node.

        :param ids: If true, includes the ids with the node type names.
        :type ids: bool

        :param include_linenos: If true, includes the line numbers and
            column offsets.
        :type include_linenos: bool

        :param ast_state: If true, includes information derived from
            the whole AST like local and global variables.
        :type ast_state: bool

        :param indent: A string to use to indent the output string.
        :type indent: str

        :param max_depth: If set to a positive integer, won't return
            nodes deeper than max_depth in the string.
        :type max_depth: int

        :param max_width: Attempt to format the output string to stay
            within this number of characters, but can exceed it under some
            circumstances. Only positive integer values are valid, the default is 80.
        :type max_width: int

        :returns: The string representation of the AST.
        :rtype: str
        rd   r   c                s\   t j| tt  ddd}||d  | fdd|dd D  t|dkS )zOutputs a representation of a non-tuple/list, non-node that's
            contained within an AST, including strings.
            r   )rk   Tr   c                s   g | ]} | qS r   r   )r.   r}   )
cur_indentr   r   
<listcomp>A  s    z8NodeNG.repr_tree.<locals>._repr_tree.<locals>.<listcomp>N)rs   rt   maxrq   ru   rv   extend)r   ry   doner   depthr{   )	max_width)r   r   
_repr_tree8  s     z$NodeNG.repr_tree.<locals>._repr_treec                s  |7 }| d | sd}nt| dkr> | d ||||}nt| dkr | d ||||}|sn| d n| d | |  | d ||||p|}nf| d | | x8| d	d
 D ](} ||||| | d | | qW  | d
 |||| d}| d |S )zFOutputs a representation of a sequence that's contained within an AST.[Fr   r   rh   z, z,

Nr   T])rv   rq   )r   ry   r   r   r   brokenr   )r   rj   r   r   	_repr_seqE  s.    






z#NodeNG.repr_tree.<locals>._repr_seqc                s  | |kr,| dt| jt| f   dS ||  rP|krP| d dS |d7 }|7 }r| dt| jt| f  n| dt| j  g }r|d || j || j r|| j |sd}nt	|dkr| d|d	    t
| |d	 ||||}n| d
 | | xN|dd D ]>}| d|   t
| ||||| | d | | q8W | d|d    t
| |d |||| d}| d |S )z4Outputs a strings representation of an astroid node.z<Recursion on %s with id=%sFz...r   z
%s<0x%x>(
z%s()rU   rV   z%s=r   r   Nr   z,
T))rv   r)   rp   r   addr   rr   rc   _other_other_fieldsrq   re   )r   ry   r   r   r   ro   r   rz   )r   	ast_stateidsinclude_linenosrj   	max_depthr   r   
_repr_noded  sN    






z$NodeNG.repr_tree.<locals>._repr_node)rd   r   )rd   r   )rd   r   )_singledispatchregisterr   r   rT   setrw   )
rW   r   r   r   rj   r   r   r   r   ry   r   )r   r   r   r   rj   r   r   r   	repr_tree  s    &/zNodeNG.repr_treec             C   s   t jS )ak  Determine the boolean value of this node.

        The boolean value of a node can have three
        possible values:

            * False: For instance, empty data structures,
              False, empty strings, instances which return
              explicitly False from the __nonzero__ / __bool__
              method.
            * True: Most of constructs are True by default:
              classes, functions, modules etc
            * Uninferable: The inference engine is uncertain of the
              node's value.

        :returns: The boolean value of this node.
        :rtype: bool or Uninferable
        )r   r   )rW   r   r   r   
bool_value  s    zNodeNG.bool_valuec             C   s   t | jjtt S )N)OP_PRECEDENCErY   r:   rp   rq   )rW   r   r   r   op_precedence  s    zNodeNG.op_precedencec             C   s   dS )NTr   )rW   r   r   r   op_left_associative  s    zNodeNG.op_left_associative)NNN)N)N)N)FFFr   r   ri   ):rp   
__module____qualname____doc__r   optional_assignis_function	is_lambdarU   rV   r   rc   rr   r   rZ   rX   r   rg   r~   r   r   r   r   r   r   r   r   r   r   r!   r   r   r   r   cachedpropertyr   r   r   r   r   r   cachedr   r   r   r   r   r[   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rT      sr   	

!




		
     
rT   c               @   s$   e Zd ZdZdZdd Zdd ZdS )	Statementz&Statement node adding a few attributesTc             C   s<   | j | }|| }y||d  S  tk
r6   Y nX dS )z|The next sibling statement node.

        :returns: The next sibling statement node.
        :rtype: NodeNG or None
        r   N)r   r   r,   r;   )rW   stmtsr,   r   r   r   r     s    
zStatement.next_siblingc             C   s.   | j | }|| }|dkr*||d  S dS )zThe previous sibling statement.

        :returns: The previous sibling statement node.
        :rtype: NodeNG or None
        r   N)r   r   r,   )rW   r   r,   r   r   r   r     s
    
zStatement.previous_siblingN)rp   r   r   r   r   r   r   r   r   r   r   r     s   r   c                   sb   e Zd ZdZdZd fdd	Zdd Zeddd	Zd
d Z	dd Z
ejdd Zdd Z  ZS )_BaseContainerz.Base class for Set, FrozenSet, Tuple and List.)r   Nc                s   g | _ tt| ||| dS )aa  
        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)r   superr   rX   )rW   rU   rV   r   )r:   r   r   rX     s    z_BaseContainer.__init__c             C   s
   || _ dS )zDo some setup after initialisation.

        :param elts: The list of elements the that node contains.
        :type elts: list(NodeNG)
        N)r   )rW   r   r   r   r   postinit  s    z_BaseContainer.postinitc             C   s*   |  }|dkrg |_ ndd |D |_ |S )a  Create a node of this type from the given list of elements.

        :param elts: The list of elements that the node should contain.
        :type elts: list(NodeNG)

        :returns: A new node containing the given elements.
        :rtype: NodeNG
        Nc             S   s   g | ]}t |qS r   )const_factory)r.   er   r   r   r   	  s    z1_BaseContainer.from_constants.<locals>.<listcomp>)r   )clsr   r   r   r   r   from_constants  s
    
z_BaseContainer.from_constantsc             C   s   | j S )zAn iterator over the elements this node contains.

        :returns: The contents of this node.
        :rtype: iterable(NodeNG)
        )r   )rW   r   r   r   itered  s    z_BaseContainer.iteredc             C   s
   t | jS )zDetermine the boolean value of this node.

        :returns: The boolean value of this node.
        :rtype: bool or Uninferable
        )boolr   )rW   r   r   r   r     s    z_BaseContainer.bool_valuec             C   s   dS )zyGet the name of the type that this node represents.

        :returns: The name of the type.
        :rtype: str
        Nr   )rW   r   r   r   pytype  s    z_BaseContainer.pytypec             c   s   | j E d H  d S )N)r   )rW   r   r   r   r   $  s    z_BaseContainer.get_children)NNN)N)rp   r   r   r   rc   rX   r   classmethodr   r   r   abcabstractmethodr   r   __classcell__r   r   )r:   r   r     s   r   )	metaclassc               @   s:   e Zd ZdZedddd Zdd Zdd	 Zd
d ZdS )LookupMixInz+Mixin to look up a name in the right scope.N)maxsizec             C   s   |   | |S )ad  Lookup where the given variable is assigned.

        The lookup starts from self's scope. If self is not a frame itself
        and the name is found in the inner frame locals, statements will be
        filtered to remove ignorable statements according to self's location.

        :param name: The name of the variable to find assignments for.
        :type name: str

        :returns: The scope node and the list of assignments associated to the
            given name according to the scope where it has been found (locals,
            globals or builtin).
        :rtype: tuple(str, list(NodeNG))
        )r   Zscope_lookup)rW   ra   r   r   r   lookup+  s    zLookupMixIn.lookupc             C   s$   |  |\}}t }t|||S )a
  Lookup the inferred values of the given variable.

        :param name: The variable name to find values for.
        :type name: str

        :returns: The inferred values of the statements returned from
            :meth:`lookup`.
        :rtype: iterable
        )r   
contextmodZInferenceContextr   Z_infer_stmts)rW   ra   r   r   r   r   r   r   ilookup=  s    
zLookupMixIn.ilookupc                sB   dd |D }t |dkr>tdd |D r> fdd|D }|S )Nc             S   s   g | ]}||  fqS r   )r   )r.   r   r   r   r   r   L  s    z=LookupMixIn._get_filtered_node_statements.<locals>.<listcomp>r   c             s   s   | ]\}}t |tV  qd S )N)r   ExceptHandler)r.   _r   r   r   r   r0   P  s    z<LookupMixIn._get_filtered_node_statements.<locals>.<genexpr>c                s"   g | ]\}}|  r||fqS r   )r   )r.   r   r   )rW   r   r   r   S  s    )rq   r5   )rW   r   
statementsr   )rW   r   _get_filtered_node_statementsK  s
    z)LookupMixIn._get_filtered_node_statementsc          	   C   s6  |dkr|   j  }n$|   }|  |kr<|jr<|j  }|  }||krt|jdk	rt|jdk	sht||j| }nd}g }g }| |}	x|	D ]\}
}|j|  krdkrn nP ||krt| rqt|
dst|
|
 |
 j	f|

 }|
| rP || |
||\}}|rP |j}|rF|| rF|
g}|jg}qy||j}W n tk
rl   Y nbX || 
 |rq|st|| |
s|
jr|
 dks|
j|| jkr||= ||= t|
tr|s|j|jkrg }g }nt|
trg }g }qt| |
s||
 ||j qW |S )ap  Filter the given list of statements to remove ignorable statements.

        If self is not a frame itself and the name is found in the inner
        frame locals, statements will be filtered to remove ignorable
        statements according to self's location.

        :param stmts: The statements to filter.
        :type stmts: list(NodeNG)

        :param frame: The frame that all of the given statements belong to.
        :type frame: NodeNG

        :param offset: The line offset to filter statements up to.
        :type offset: int

        :returns: The filtered statements.
        :rtype: list(NodeNG)
        r   Nr   assign_typeZPartialFunction)r   r   r   r   r   r   is_from_decoratorhasattrr   localsr   r   _get_filtered_stmtsr   r   r,   
ValueErrorr%   r   qnamera   r   
AssignNameDelNamerv   )rW   r   r   offsetZmyframemystmtr   Z_stmtsZ_stmt_parentsr   r   r   r   r   r   Zpindexr   r   r   _filter_stmtsW  sr    



zLookupMixIn._filter_stmts)	rp   r   r   r   r   r   r   r   r   r   r   r   r   r   (  s
   r   c                   s&   e Zd ZdZdZd fdd	Z  ZS )r   a  Variation of :class:`ast.Assign` representing assignment to a name.

    An :class:`AssignName` is the name of something that is assigned to.
    This includes variables defined in a function signature or in a loop.

    >>> node = astroid.extract_node('variable = range(10)')
    >>> node
    <Assign l.1 at 0x7effe1db8550>
    >>> list(node.get_children())
    [<AssignName.variable l.1 at 0x7effe1db8748>, <Call l.1 at 0x7effe1db8630>]
    >>> list(node.get_children())[0].as_string()
    'variable'
    )ra   Nc                s   || _ tt| ||| dS )a  
        :param name: The name that is assigned to.
        :type name: str or None

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)ra   r   r   rX   )rW   ra   rU   rV   r   )r:   r   r   rX      s    zAssignName.__init__)NNNN)rp   r   r   r   rr   rX   r   r   r   )r:   r   r     s   r   c                   s&   e Zd ZdZdZd fdd	Z  ZS )r   aQ  Variation of :class:`ast.Delete` representing deletion of a name.

    A :class:`DelName` is the name of something that is deleted.

    >>> node = astroid.extract_node("del variable #@")
    >>> list(node.get_children())
    [<DelName.variable l.1 at 0x7effe1da4d30>]
    >>> list(node.get_children())[0].as_string()
    'variable'
    )ra   Nc                s   || _ tt| ||| dS )a  
        :param name: The name that is being deleted.
        :type name: str or None

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)ra   r   r   rX   )rW   ra   rU   rV   r   )r:   r   r   rX   (  s    zDelName.__init__)NNNN)rp   r   r   r   rr   rX   r   r   r   )r:   r   r     s   r   c                   s.   e Zd ZdZdZd fdd	Zdd Z  ZS )	Namea  Class representing an :class:`ast.Name` node.

    A :class:`Name` node is something that is named, but not covered by
    :class:`AssignName` or :class:`DelName`.

    >>> node = astroid.extract_node('range(10)')
    >>> node
    <Call l.1 at 0x7effe1db8710>
    >>> list(node.get_children())
    [<Name.range l.1 at 0x7effe1db86a0>, <Const.int l.1 at 0x7effe1db8518>]
    >>> list(node.get_children())[0].as_string()
    'range'
    )ra   Nc                s   || _ tt| ||| dS )a  
        :param name: The name that this node refers to.
        :type name: str or None

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)ra   r   r   rX   )rW   ra   rU   rV   r   )r:   r   r   rX   Q  s    zName.__init__c             c   s*   | V  x|   D ]}| E d H  qW d S )N)r   r   )rW   r   r   r   r   r   h  s    zName._get_name_nodes)NNNN)rp   r   r   r   rr   rX   r   r   r   r   )r:   r   r   @  s   r   c                   s   e Zd ZdZdZdZdZdZd fdd	ZdddZ	d	d
 Z
ej fddZdd Zdd Zdd ZdddZdd Z  ZS )	Argumentsa;  Class representing an :class:`ast.arguments` node.

    An :class:`Arguments` node represents that arguments in a
    function definition.

    >>> node = astroid.extract_node('def foo(bar): pass')
    >>> node
    <FunctionDef.foo l.1 at 0x7effe1db8198>
    >>> node.args
    <Arguments l.1 at 0x7effe1db82e8>
    )argsdefaults
kwonlyargskw_defaultsannotationsvarargannotationkwargannotationkwonlyargs_annotationsN)varargkwargc                sF   t t| j|d || _|| _g | _g | _g | _g | _g | _	g | _
dS )a9  
        :param vararg: The name of the variable length arguments.
        :type vararg: str or None

        :param kwarg: The name of the variable length keyword arguments.
        :type kwarg: str or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        )r   N)r   r   rX   r  r  r   r   r   r   r   r  )rW   r  r  r   )r:   r   r   rX     s    zArguments.__init__c	       	      C   s4   || _ || _|| _|| _|| _|| _|| _|| _dS )a  Do some setup after initialisation.

        :param args: The names of the required arguments.
        :type args: list(AssignName)

        :param defaults: The default values for arguments that can be passed
            positionally.
        :type defaults: list(NodeNG)

        :param kwonlyargs: The keyword arguments that cannot be passed
            positionally.
        :type kwonlyargs: list(AssignName)

        :param kw_defaults: The default values for keyword arguments that
            cannot be passed positionally.
        :type kw_defaults: list(NodeNG)

        :param annotations: The type annotations of arguments that can be
            passed positionally.
        :type annotations: list(NodeNG)

        :param kwonlyargs_annotations: The type annotations of arguments that
            cannot be passed positionally. This should always be passed in
            Python 3.
        :type kwonlyargs_annotations: list(NodeNG)

        :param varargannotation: The type annotation for the variable length
            arguments.
        :type varargannotation: NodeNG

        :param kwargannotation: The type annotation for the variable length
            keyword arguments.
        :type kwargannotation: NodeNG
        N)r   r   r   r   r   r  r   r  )	rW   r   r   r   r   r   r  r   r  r   r   r   r     s    -zArguments.postinitc             C   s   | j |kr|S d S )N)r   )rW   r   ra   r   r   r   r     s    
zArguments._infer_namec                s   t t| j}t|| jjpdS )zaThe first line that this node appears on in the source code.

        :type: int or None
        r   )r   r   r   r   r   )rW   rU   )r:   r   r   r     s    zArguments.fromlinenoc          	   C   s   g }| j r(|t| j | jt| dd | jr>|d| j  | jrl| jsT|d |t| j| j| j | j	r|d| j	  d
|S )zoGet the arguments formatted as string.

        :returns: The formatted arguments.
        :rtype: str
        r   Nz*%srN   z**%sz, )r   rv   _format_argsr   re   r  r   r   r  r  rw   )rW   ry   r   r   r   format_args  s     
zArguments.format_argsc             C   s   t || jd }|dk	rB|t| jt| j  }|dkrB| j| S t || jd }|dk	rr| j| dk	rr| j| S tj| j|ddS )zGet the default value for an argument.

        :param argname: The name of the argument to get the default value for.
        :type argname: str

        :raises NoDefault: If there is no default value defined for the
            given argument.
        r   N)r   ra   )		_find_argr   rq   r   r   r   r   Z	NoDefaultr   )rW   argnameiidxr   r   r   default_value9  s    	

zArguments.default_valuec             C   sL   || j krdS || jkrdS | |dd dk	pJ| joJt|| jdd dk	S )zCheck if the given name is defined in the arguments.

        :param name: The name to check for.
        :type name: str

        :returns: True if the given name is defined in the arguments,
            False otherwise.
        :rtype: bool
        Tr   N)r  r  find_argnamer   r  )rW   ra   r   r   r   is_argumentL  s    


zArguments.is_argumentFc             C   s   | j rt|| j |S dS )a  Get the index and :class:`AssignName` node for given name.

        :param argname: The name of the argument to search for.
        :type argname: str

        :param rec: Whether or not to include arguments in unpacked tuples
            in the search.
        :type rec: bool

        :returns: The index and node for the argument.
        :rtype: tuple(str or None, AssignName or None)
        )NN)r   r  )rW   r  recr   r   r   r  `  s    zArguments.find_argnamec             c   s   | j pdE d H  | jE d H  | jE d H  x| jD ]}|d k	r0|V  q0W x| jD ]}|d k	rN|V  qNW | jd k	rv| jV  | jd k	r| jV  x| jD ]}|d k	r|V  qW d S )Nr   )r   r   r   r   r   r   r  r  )rW   r   r   r   r   r   q  s     



zArguments.get_children)NNN)NNN)F)rp   r   r   r   rc   r   r  rr   rX   r   r   r   r   r   r  r  r  r  r   r   r   r   )r:   r   r   o  s    	C  
-	
r   Fc             C   sX   xRt |D ]F\}}t|tr>|rPt| |j}|d d k	rP|S q
|j| kr
||fS q
W dS )Nr   )NN)	enumerater   r   r  r   ra   )r  r   r  r	  argfoundr   r   r   r    s    

r  c       
      C   s   g }| d krdS |d krg }|d k	r4t | t | }t| |}xt|D ]\}\}}t|trv|dt|j  qJ|j	}	|d k	r|	d|
  7 }	||	 |d k	rJ||krJ|||  d k	rJ|d  d|||  
  7  < qJW d|S )Nrd   z(%s):r   =z, )rq   	itertoolszip_longestr  r   r   rv   r  r   ra   r   rw   )
r   r   r   valuesZdefault_offsetZpackedr	  r  
annotationr  r   r   r   r    s&    

$r  c                   s@   e Zd ZdZdZdZdZd fdd	ZdddZd	d
 Z	  Z
S )
AssignAttraz  Variation of :class:`ast.Assign` representing assignment to an attribute.

    >>> node = astroid.extract_node('self.attribute = range(10)')
    >>> node
    <Assign l.1 at 0x7effe1d521d0>
    >>> list(node.get_children())
    [<AssignAttr.attribute l.1 at 0x7effe1d52320>, <Call l.1 at 0x7effe1d522e8>]
    >>> list(node.get_children())[0].as_string()
    'self.attribute'
    )expr)rb   Nc                s   || _ tt| ||| dS )a  
        :param attrname: The name of the attribute being assigned to.
        :type attrname: str or None

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)rb   r   r  rX   )rW   rb   rU   rV   r   )r:   r   r   rX     s    zAssignAttr.__init__c             C   s
   || _ dS )zDo some setup after initialisation.

        :param expr: What has the attribute that is being assigned to.
        :type expr: NodeNG or None
        N)r  )rW   r  r   r   r   r     s    zAssignAttr.postinitc             c   s   | j V  d S )N)r  )rW   r   r   r   r     s    zAssignAttr.get_children)NNNN)N)rp   r   r   r   rc   rr   r  rX   r   r   r   r   r   )r:   r   r    s   

r  c               @   s.   e Zd ZdZdZdZdZdddZdd ZdS )	AssertzClass representing an :class:`ast.Assert` node.

    An :class:`Assert` node represents an assert statement.

    >>> node = astroid.extract_node('assert len(things) == 10, "Not enough things"')
    >>> node
    <Assert l.1 at 0x7effe1d527b8>
    )testfailNc             C   s   || _ || _dS )zDo some setup after initialisation.

        :param test: The test that passes or fails the assertion.
        :type test: NodeNG or None

        :param fail: The message shown when the assertion fails.
        :type fail: NodeNG or None
        N)r  r  )rW   r  r  r   r   r   r     s    	zAssert.postinitc             c   s   | j V  | jd k	r| jV  d S )N)r  r  )rW   r   r   r   r     s    
zAssert.get_children)NN)	rp   r   r   r   rc   r  r  r   r   r   r   r   r   r    s   
r  c               @   sL   e Zd ZdZdZdZdZdZdZdddZ	dd Z
ejd	d
 Zdd ZdS )AssignzClass representing an :class:`ast.Assign` node.

    An :class:`Assign` is a statement where something is explicitly
    asssigned to.

    >>> node = astroid.extract_node('variable = range(10)')
    >>> node
    <Assign l.1 at 0x7effe1db8550>
    )targetsr'   )type_annotationNc             C   s   || _ || _|| _dS )zDo some setup after initialisation.

        :param targets: What is being assigned to.
        :type targets: list(NodeNG) or None

        :param value: The value being assigned to the variables.
        :type: NodeNG or None
        N)r  r'   r  )rW   r  r'   r  r   r   r   r   +  s    	zAssign.postinitc             c   s   | j E d H  | jV  d S )N)r  r'   )rW   r   r   r   r   8  s    zAssign.get_childrenc             C   s   | gt | j  S )N)r   r'   r   )rW   r   r   r   r   =  s    zAssign._get_assign_nodesc             c   s   | j  E d H  d S )N)r'   r   )rW   r   r   r   r   A  s    z$Assign._get_yield_nodes_skip_lambdas)NNN)rp   r   r   r   rc   r   r  r'   r  r   r   r   r   r   r   r   r   r   r   r    s   	
r  c               @   s:   e Zd ZdZdZdZdZdZdZdZ	d	ddZ
dd ZdS )
	AnnAssignzClass representing an :class:`ast.AnnAssign` node.

    An :class:`AnnAssign` is an assignment with a type annotation.

    >>> node = astroid.extract_node('variable: List[int] = range(10)')
    >>> node
    <AnnAssign l.1 at 0x7effe1d4c630>
    )targetr  r'   )simpleNc             C   s   || _ || _|| _|| _dS )a  Do some setup after initialisation.

        :param target: What is being assigned to.
        :type target: NodeNG

        :param annotation: The type annotation of what is being assigned to.
        :type: NodeNG

        :param simple: Whether :attr:`target` is a pure name
            or a complex statement.
        :type simple: int

        :param value: The value being assigned to the variables.
        :type: NodeNG or None
        N)r!  r  r'   r"  )rW   r!  r  r"  r'   r   r   r   r   f  s    zAnnAssign.postinitc             c   s&   | j V  | jV  | jd k	r"| jV  d S )N)r!  r  r'   )rW   r   r   r   r   {  s    
zAnnAssign.get_children)N)rp   r   r   r   rc   rr   r!  r  r'   r"  r   r   r   r   r   r   r   E  s   
r   c                   sX   e Zd ZdZdZdZdZdZd fdd	ZdddZ	dd	d
Z
dddZdd Z  ZS )	AugAssignzClass representing an :class:`ast.AugAssign` node.

    An :class:`AugAssign` is an assignment paired with an operator.

    >>> node = astroid.extract_node('variable += 1')
    >>> node
    <AugAssign l.1 at 0x7effe1db4d68>
    )r!  r'   )rB   Nc                s   || _ tt| ||| dS )a  
        :param op: The operator that is being combined with the assignment.
            This includes the equals sign.
        :type op: str or None

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)rB   r   r#  rX   )rW   rB   rU   rV   r   )r:   r   r   rX     s    zAugAssign.__init__c             C   s   || _ || _dS )zDo some setup after initialisation.

        :param target: What is being assigned to.
        :type target: NodeNG or None

        :param value: The value being assigned to the variable.
        :type: NodeNG or None
        N)r!  r'   )rW   r!  r'   r   r   r   r     s    	zAugAssign.postinitc             C   s   t d S )N)NotImplementedError)rW   r   r   r   r   _infer_augassign  s    zAugAssign._infer_augassignc             C   s6   y| j |d}dd |D S  tjk
r0   g S X dS )a&  Get a list of type errors which can occur during inference.

        Each TypeError is represented by a :class:`BadBinaryOperationMessage` ,
        which holds the original exception.

        :returns: The list of possible type errors.
        :rtype: list(BadBinaryOperationMessage)
        )r   c             S   s   g | ]}t |tjr|qS r   )r   r   BadBinaryOperationMessage)r.   ry   r   r   r   r     s   z)AugAssign.type_errors.<locals>.<listcomp>N)r%  r   r*   )rW   r   resultsr   r   r   type_errors  s    	zAugAssign.type_errorsc             c   s   | j V  | jV  d S )N)r!  r'   )rW   r   r   r   r     s    zAugAssign.get_children)NNNN)NN)N)N)rp   r   r   r   rc   rr   r!  r'   rX   r   r%  r(  r   r   r   r   )r:   r   r#    s   


r#  c               @   s"   e Zd ZdZdZdZdddZdS )Repra  Class representing an :class:`ast.Repr` node.

    A :class:`Repr` node represents the backtick syntax,
    which is a deprecated alias for :func:`repr` removed in Python 3.

    >>> node = astroid.extract_node('`variable`')
    >>> node
    <Repr l.1 at 0x7fa0951d75d0>
    )r'   Nc             C   s
   || _ dS )zDo some setup after initialisation.

        :param value: What is having :func:`repr` called on it.
        :type value: NodeNG or None
        N)r'   )rW   r'   r   r   r   r     s    zRepr.postinit)N)rp   r   r   r   rc   r'   r   r   r   r   r   r)    s   	r)  c                   sh   e Zd ZdZdZdZdZdZd fdd	ZdddZ	dd	d
Z
dddZdd Zdd Zdd Z  ZS )BinOpzClass representing an :class:`ast.BinOp` node.

    A :class:`BinOp` node is an application of a binary operator.

    >>> node = astroid.extract_node('a + b')
    >>> node
    <BinOp l.1 at 0x7f23b2e8cfd0>
    )leftright)rB   Nc                s   || _ tt| ||| dS )a  
        :param op: The operator.
        :type: str or None

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)rB   r   r*  rX   )rW   rB   rU   rV   r   )r:   r   r   rX     s    zBinOp.__init__c             C   s   || _ || _dS )a  Do some setup after initialisation.

        :param left: What is being applied to the operator on the left side.
        :type left: NodeNG or None

        :param right: What is being applied to the operator on the right side.
        :type right: NodeNG or None
        N)r+  r,  )rW   r+  r,  r   r   r   r   %  s    	zBinOp.postinitc             C   s   t d S )N)r$  )rW   r   r   r   r   _infer_binop2  s    zBinOp._infer_binopc             C   s6   y| j |d}dd |D S  tjk
r0   g S X dS )a%  Get a list of type errors which can occur during inference.

        Each TypeError is represented by a :class:`BadBinaryOperationMessage`,
        which holds the original exception.

        :returns: The list of possible type errors.
        :rtype: list(BadBinaryOperationMessage)
        )r   c             S   s   g | ]}t |tjr|qS r   )r   r   r&  )r.   ry   r   r   r   r   A  s   z%BinOp.type_errors.<locals>.<listcomp>N)r-  r   r*   )rW   r   r'  r   r   r   r(  5  s    	zBinOp.type_errorsc             c   s   | j V  | jV  d S )N)r+  r,  )rW   r   r   r   r   H  s    zBinOp.get_childrenc             C   s
   t | j S )N)r   rB   )rW   r   r   r   r   L  s    zBinOp.op_precedencec             C   s
   | j dkS )Nz**)rB   )rW   r   r   r   r   O  s    zBinOp.op_left_associative)NNNN)NN)N)N)rp   r   r   r   rc   rr   r+  r,  rX   r   r-  r(  r   r   r   r   r   r   )r:   r   r*    s   


r*  c                   sH   e Zd ZdZdZdZdZd fdd	ZdddZd	d
 Z	dd Z
  ZS )BoolOpzClass representing an :class:`ast.BoolOp` node.

    A :class:`BoolOp` is an application of a boolean operator.

    >>> node = astroid.extract_node('a and b')
    >>> node
    <BinOp l.1 at 0x7f23b2e71c50>
    )r  )rB   Nc                s   || _ tt| ||| dS )a  
        :param op: The operator.
        :type: str or None

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)rB   r   r.  rX   )rW   rB   rU   rV   r   )r:   r   r   rX   f  s    zBoolOp.__init__c             C   s
   || _ dS )zDo some setup after initialisation.

        :param values: The values being applied to the operator.
        :type values: list(NodeNG) or None
        N)r  )rW   r  r   r   r   r   }  s    zBoolOp.postinitc             c   s   | j E d H  d S )N)r  )rW   r   r   r   r     s    zBoolOp.get_childrenc             C   s
   t | j S )N)r   rB   )rW   r   r   r   r     s    zBoolOp.op_precedence)NNNN)N)rp   r   r   r   rc   rr   r  rX   r   r   r   r   r   r   )r:   r   r.  T  s   
r.  c               @   s   e Zd ZdZdS )BreakzClass representing an :class:`ast.Break` node.

    >>> node = astroid.extract_node('break')
    >>> node
    <Break l.1 at 0x7f23b2e9e5c0>
    N)rp   r   r   r   r   r   r   r   r/    s   r/  c               @   sJ   e Zd ZdZdZdZdZdZdddZe	dd Z
e	dd	 Zd
d ZdS )CallzClass representing an :class:`ast.Call` node.

    A :class:`Call` node is a call to a function, method, etc.

    >>> node = astroid.extract_node('function()')
    >>> node
    <Call l.1 at 0x7f23b2e71eb8>
    )r   r   keywordsNc             C   s   || _ || _|| _dS )ab  Do some setup after initialisation.

        :param func: What is being called.
        :type func: NodeNG or None

        :param args: The positional arguments being given to the call.
        :type args: list(NodeNG) or None

        :param keywords: The keyword arguments being given to the call.
        :type keywords: list(NodeNG) or None
        N)r   r   r1  )rW   r   r   r1  r   r   r   r     s    zCall.postinitc             C   s   | j pg }dd |D S )zVThe positional arguments that unpack something.

        :type: list(Starred)
        c             S   s   g | ]}t |tr|qS r   )r   Starred)r.   r  r   r   r   r     s    z!Call.starargs.<locals>.<listcomp>)r   )rW   r   r   r   r   starargs  s    
zCall.starargsc             C   s   | j pg }dd |D S )zSThe keyword arguments that unpack something.

        :type: list(Keyword)
        c             S   s   g | ]}|j d kr|qS )N)r  )r.   keywordr   r   r   r     s    zCall.kwargs.<locals>.<listcomp>)r1  )rW   r1  r   r   r   r^     s    
zCall.kwargsc             c   s(   | j V  | jE d H  | jpdE d H  d S )Nr   )r   r   r1  )rW   r   r   r   r     s    zCall.get_children)NNN)rp   r   r   r   rc   r   r   r1  r   propertyr3  r^   r   r   r   r   r   r0    s   
		r0  c               @   s6   e Zd ZdZdZdZdZd
ddZdd Zdd	 Z	dS )rH   a5  Class representing an :class:`ast.Compare` node.

    A :class:`Compare` node indicates a comparison.

    >>> node = astroid.extract_node('a <= b <= c')
    >>> node
    <Compare l.1 at 0x7f23b2e9e6d8>
    >>> node.ops
    [('<=', <Name.b l.1 at 0x7f23b2e9e2b0>), ('<=', <Name.c l.1 at 0x7f23b2e9e390>)]
    )r+  rA   Nc             C   s   || _ || _dS )aH  Do some setup after initialisation.

        :param left: The value at the left being applied to a comparison
            operator.
        :type left: NodeNG or None

        :param ops: The remainder of the operators
            and their relevant right hand value.
        :type ops: list(tuple(str, NodeNG)) or None
        N)r+  rA   )rW   r+  rA   r   r   r   r     s    zCompare.postinitc             c   s&   | j V  x| jD ]\}}|V  qW dS )zGet the child nodes below this node.

        Overridden to handle the tuple fields and skip returning the operator
        strings.

        :returns: The children.
        :rtype: iterable(NodeNG)
        N)r+  rA   )rW   r   Z
comparatorr   r   r   r    	  s    	zCompare.get_childrenc             C   s   | j d d S )zsAn optimized version of list(get_children())[-1]

        :returns: The last child.
        :rtype: NodeNG
        r   r   )rA   )rW   r   r   r   r   	  s    zCompare.last_child)NN)
rp   r   r   r   rc   r+  rA   r   r   r   r   r   r   r   rH     s   

c                   s`   e Zd ZdZdZdZdZdZdZdZ	d fdd	Z
dddZd	Zd
d Zdd Zdd Z  ZS )Comprehensiona  Class representing an :class:`ast.comprehension` node.

    A :class:`Comprehension` indicates the loop inside any type of
    comprehension including generator expressions.

    >>> node = astroid.extract_node('[x for x in some_values]')
    >>> list(node.get_children())
    [<Name.x l.1 at 0x7f23b2e352b0>, <Comprehension l.1 at 0x7f23b2e35320>]
    >>> list(node.get_children())[1].as_string()
    'for x in some_values'
    )r!  r\   ifs)is_asyncNc                s   t t|   || _dS )zi
        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)r   r6  rX   r   )rW   r   )r:   r   r   rX   <	  s    zComprehension.__init__c             C   s   || _ || _|| _|| _dS )a  Do some setup after initialisation.

        :param target: What is assigned to by the comprehension.
        :type target: NodeNG or None

        :param iter: What is iterated over by the comprehension.
        :type iter: NodeNG or None

        :param ifs: The contents of any if statements that filter
            the comprehension.
        :type ifs: list(NodeNG) or None

        :param is_async: Whether this is an asynchronous comprehension or not.
        :type: bool or None
        N)r!  r\   r7  r8  )rW   r!  r\   r7  r8  r   r   r   r   E	  s    zComprehension.postinitTc             C   s   | S )zwThe type of assignment that this node performs.

        :returns: The assignment type.
        :rtype: NodeNG
        r   )rW   r   r   r   r   `	  s    zComprehension.assign_typec             C   s@   | |kr"t |ttfr8|gdfS n|  |kr8|gdfS |dfS )zmethod used in filter_stmtsTF)r   r&   r   r   )rW   Zlookup_noder   r   r   r   r   r   r   h	  s    
z!Comprehension._get_filtered_stmtsc             c   s    | j V  | jV  | jE d H  d S )N)r!  r\   r7  )rW   r   r   r   r   v	  s    zComprehension.get_children)N)NNNN)rp   r   r   r   rc   rr   r!  r\   r7  r8  rX   r   r   r   r   r   r   r   r   )r:   r   r6  	  s   	
r6  c                   s\   e Zd ZdZdZd fdd	Z fddZddd	Zd
d Zdd Z	dd Z
dd Z  ZS )r&   a  Class representing any constant including num, str, bool, None, bytes.

    >>> node = astroid.extract_node('(5, "This is a string.", True, None, b"bytes")')
    >>> node
    <Tuple.tuple l.1 at 0x7f23b2e358d0>
    >>> list(node.get_children())
    [<Const.int l.1 at 0x7f23b2e35940>,
    <Const.str l.1 at 0x7f23b2e35978>,
    <Const.bool l.1 at 0x7f23b2e359b0>,
    <Const.NoneType l.1 at 0x7f23b2e359e8>,
    <Const.bytes l.1 at 0x7f23b2e35a20>]
    )r'   Nc                s   || _ tt| ||| dS )a  
        :param value: The value that the constant represents.
        :type value: object

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)r'   r   r&   rX   )rW   r'   rU   rV   r   )r:   r   r   rX   	  s    zConst.__init__c                s   |dkrt t |S )Nr'   )AttributeErrorr   __getattr__)rW   ra   )r:   r   r   r:  	  s    zConst.__getattr__c          
   C   s   t |tr|j}n,t |tr*t||d}ntdt|y"t | jt	t
fr^t| j| S W nj tk
r } ztjd| ||d|W dd}~X Y n6 tk
r } ztjd| ||d|W dd}~X Y nX td| | jf dS )a%  Get an item from this node if subscriptable.

        :param index: The node to use as a subscript index.
        :type index: Const or Slice

        :raises AstroidTypeError: When the given index cannot be used as a
            subscript index, or if this node is not subscriptable.
        )r   z(Could not use type {} as subscript indexzIndex {index!r} out of range)r1   r   r,   r   NzType error {error!r}z%r (value=%s))r   r&   r'   r9   r8   r   r7   formatr)   strbytesr;   r<   r=   )rW   r,   r   Zindex_valuer?   r   r   r   getitem	  s*    	

zConst.getitemc             C   s   dS )a  Check if the node has a custom __getattr__ or __getattribute__.

        :returns: True if the class has a custom
            __getattr__ or __getattribute__, False otherwise.
            For a :class:`Const` this is always ``False``.
        :rtype: bool
        Fr   )rW   r   r   r   has_dynamic_getattr	  s    zConst.has_dynamic_getattrc             C   s   t | jtr| jS t dS )zAn iterator over the elements this node contains.

        :returns: The contents of this node.
        :rtype: iterable(str)

        :raises TypeError: If this node does not represent something that is iterable.
        N)r   r'   r<  r=   )rW   r   r   r   r   	  s    zConst.iteredc             C   s
   | j  S )zyGet the name of the type that this node represents.

        :returns: The name of the type.
        :rtype: str
        )_proxiedr   )rW   r   r   r   r   	  s    zConst.pytypec             C   s
   t | jS )zzDetermine the boolean value of this node.

        :returns: The boolean value of this node.
        :rtype: bool
        )r   r'   )rW   r   r   r   r   	  s    zConst.bool_value)NNN)N)rp   r   r   r   rr   rX   r:  r>  r?  r   r   r   r   r   r   )r:   r   r&   }	  s   
$
r&   c               @   s   e Zd ZdZdS )ContinuezClass representing an :class:`ast.Continue` node.

    >>> node = astroid.extract_node('continue')
    >>> node
    <Continue l.1 at 0x7f23b2e35588>
    N)rp   r   r   r   r   r   r   r   rA  	  s   rA  c               @   s0   e Zd ZdZdZdZdd Zdd Zdd	 ZdS )

Decoratorsa  A node representing a list of decorators.

    A :class:`Decorators` is the decorators that are applied to
    a method or function.

    >>> node = astroid.extract_node('''
    @property
    def my_property(self):
        return 3
    ''')
    >>> node
    <FunctionDef.my_property l.2 at 0x7f23b2e35d30>
    >>> list(node.get_children())[0]
    <Decorators l.1 at 0x7f23b2e35d68>
    )r   Nc             C   s
   || _ dS )zDo some setup after initialisation.

        :param nodes: The decorators that this node contains.
        :type nodes: list(Name or Call)
        N)r   )rW   r   r   r   r   r   
  s    zDecorators.postinitc             C   s   | j j  S )zThe first parent node defining a new scope.

        :returns: The first parent scope node.
        :rtype: Module or FunctionDef or ClassDef or Lambda or GenExpr
        )r   r   )rW   r   r   r   r   #
  s    zDecorators.scopec             c   s   | j E d H  d S )N)r   )rW   r   r   r   r   ,
  s    zDecorators.get_children)	rp   r   r   r   rc   r   r   r   r   r   r   r   r   rB  
  s   	rB  c                   s@   e Zd ZdZdZdZdZd fdd	ZdddZd	d
 Z	  Z
S )DelAttra   Variation of :class:`ast.Delete` representing deletion of an attribute.

    >>> node = astroid.extract_node('del self.attr')
    >>> node
    <Delete l.1 at 0x7f23b2e35f60>
    >>> list(node.get_children())[0]
    <DelAttr.attr l.1 at 0x7f23b2e411d0>
    )r  )rb   Nc                s   || _ tt| ||| dS )a  
        :param attrname: The name of the attribute that is being deleted.
        :type attrname: str or None

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)rb   r   rC  rX   )rW   rb   rU   rV   r   )r:   r   r   rX   B
  s    zDelAttr.__init__c             C   s
   || _ dS )zDo some setup after initialisation.

        :param expr: The name that this node represents.
        :type expr: Name or None
        N)r  )rW   r  r   r   r   r   Y
  s    zDelAttr.postinitc             c   s   | j V  d S )N)r  )rW   r   r   r   r   a
  s    zDelAttr.get_children)NNNN)N)rp   r   r   r   rc   rr   r  rX   r   r   r   r   r   )r:   r   rC  0
  s   
rC  c               @   s*   e Zd ZdZdZdZdddZdd ZdS )	DeletezClass representing an :class:`ast.Delete` node.

    A :class:`Delete` is a ``del`` statement this is deleting something.

    >>> node = astroid.extract_node('del self.attr')
    >>> node
    <Delete l.1 at 0x7f23b2e35f60>
    )r  Nc             C   s
   || _ dS )zDo some setup after initialisation.

        :param targets: What is being deleted.
        :type targets: list(NodeNG) or None
        N)r  )rW   r  r   r   r   r   v
  s    zDelete.postinitc             c   s   | j E d H  d S )N)r  )rW   r   r   r   r   ~
  s    zDelete.get_children)N)rp   r   r   r   rc   r  r   r   r   r   r   r   rD  e
  s
   
rD  c                   sn   e Zd ZdZdZd fdd	Zdd Zeddd	Zd
d Z	dd Z
dd Zdd ZdddZdd Z  ZS )DictzClass representing an :class:`ast.Dict` node.

    A :class:`Dict` is a dictionary that is created with ``{}`` syntax.

    >>> node = astroid.extract_node('{1: "1"}')
    >>> node
    <Dict.dict l.1 at 0x7f23b2e35cc0>
    )itemsNc                s   g | _ tt| ||| dS )aa  
        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)rF  r   rE  rX   )rW   rU   rV   r   )r:   r   r   rX   
  s    zDict.__init__c             C   s
   || _ dS )zDo some setup after initialisation.

        :param items: The key-value pairs contained in the dictionary.
        :type items: list(tuple(NodeNG, NodeNG))
        N)rF  )rW   rF  r   r   r   r   
  s    zDict.postinitc             C   s.   |  }|dkrg |_ ndd |  D |_ |S )zCreate a :class:`Dict` of constants from a live dictionary.

        :param items: The items to store in the node.
        :type items: dict

        :returns: The created dictionary node.
        :rtype: Dict
        Nc             S   s    g | ]\}}t |t |fqS r   )r   )r.   kvr   r   r   r   
  s    z'Dict.from_constants.<locals>.<listcomp>)rF  )r   rF  r   r   r   r   r   
  s
    
zDict.from_constantsc             C   s   dt  S )zyGet the name of the type that this node represents.

        :returns: The name of the type.
        :rtype: str
        z%s.dict)BUILTINS)rW   r   r   r   r   
  s    zDict.pytypec             c   s$   x| j D ]\}}|V  |V  qW dS )zGet the key and value nodes below this node.

        Children are returned in the order that they are defined in the source
        code, key first then the value.

        :returns: The children.
        :rtype: iterable(NodeNG)
        N)rF  )rW   r_   r'   r   r   r   r   
  s    	zDict.get_childrenc             C   s   | j r| j d d S dS )zAn optimized version of list(get_children())[-1]

        :returns: The last child, or None if no children exist.
        :rtype: NodeNG or None
        r   r   N)rF  )rW   r   r   r   r   
  s    zDict.last_childc             C   s   dd | j D S )zAn iterator over the keys this node contains.

        :returns: The keys of this node.
        :rtype: iterable(NodeNG)
        c             S   s   g | ]\}}|qS r   r   )r.   r_   r   r   r   r   r   
  s    zDict.itered.<locals>.<listcomp>)rF  )rW   r   r   r   r   
  s    zDict.iteredc          
   C   s   x| j D ]\}}t|trFy|||S  tjtjfk
rD   wY nX xB||D ]4}|tj	krbqRt|t
rRt|t
rR|j|jkrR|S qRW qW t|dS )ax  Get an item from this node.

        :param index: The node to use as a subscript index.
        :type index: Const or Slice

        :raises AstroidTypeError: When the given index cannot be used as a
            subscript index, or if this node is not subscriptable.
        :raises AstroidIndexError: If the given index does not exist in the
            dictionary.
        N)rF  r   
DictUnpackr>  r   r7   r<   r   r   r   r&   r'   )rW   r,   r   r_   r'   Zinferredkeyr   r   r   r>  
  s    

zDict.getitemc             C   s
   t | jS )zzDetermine the boolean value of this node.

        :returns: The boolean value of this node.
        :rtype: bool
        )r   rF  )rW   r   r   r   r   
  s    zDict.bool_value)NNN)N)N)rp   r   r   r   rc   rX   r   r   r   r   r   r   r   r>  r   r   r   r   )r:   r   rE  
  s   

rE  c               @   s2   e Zd ZdZdZdZd
ddZdd Zdd	 ZdS )Expra  Class representing an :class:`ast.Expr` node.

    An :class:`Expr` is any expression that does not have its value used or
    stored.

    >>> node = astroid.extract_node('method()')
    >>> node
    <Call l.1 at 0x7f23b2e352b0>
    >>> node.parent
    <Expr l.1 at 0x7f23b2e35278>
    )r'   Nc             C   s
   || _ dS )zDo some setup after initialisation.

        :param value: What the expression does.
        :type value: NodeNG or None
        N)r'   )rW   r'   r   r   r   r     s    zExpr.postinitc             c   s   | j V  d S )N)r'   )rW   r   r   r   r   $  s    zExpr.get_childrenc             c   s   | j js| j  E d H  d S )N)r'   r   r   )rW   r   r   r   r   '  s    z"Expr._get_yield_nodes_skip_lambdas)N)	rp   r   r   r   rc   r'   r   r   r   r   r   r   r   rK    s   
rK  c               @   s   e Zd ZdZdd ZdS )EllipsiszClass representing an :class:`ast.Ellipsis` node.

    An :class:`Ellipsis` is the ``...`` syntax.

    >>> node = astroid.extract_node('...')
    >>> node
    <Ellipsis l.1 at 0x7f23b2e35160>
    c             C   s   dS )zDetermine the boolean value of this node.

        :returns: The boolean value of this node.
            For an :class:`Ellipsis` this is always ``True``.
        :rtype: bool
        Tr   )rW   r   r   r   r   6  s    zEllipsis.bool_valueN)rp   r   r   r   r   r   r   r   r   rL  ,  s   rL  c               @   s   e Zd ZdZdZdS )	EmptyNodezAHolds an arbitrary object in the :attr:`LocalsDictNodeNG.locals`.N)rp   r   r   r   objectr   r   r   r   rM  @  s   rM  c               @   sL   e Zd ZdZdZdZdZdZdZdd Z	dddZ
ejd	d
 Zdd ZdS )r   a  Class representing an :class:`ast.ExceptHandler`. node.

    An :class:`ExceptHandler` is an ``except`` block on a try-except.

    >>> node = astroid.extract_node('''
        try:
            do_something()
        except Exception as error:
            print("Error!")
        ''')
    >>> node
    <TryExcept l.2 at 0x7f23b2e9d908>
    >>> >>> node.handlers
    [<ExceptHandler l.4 at 0x7f23b2e9e860>]
    )r)   ra   r   )r   Nc             c   s4   | j d k	r| j V  | jd k	r$| jV  | jE d H  d S )N)r)   ra   r   )rW   r   r   r   r   i  s
    

zExceptHandler.get_childrenc             C   s   || _ || _|| _dS )aY  Do some setup after initialisation.

        :param type: The types that the block handles.
        :type type: Tuple or NodeNG or None

        :param name: The name that the caught exception is assigned to.
        :type name: AssignName or None

        :param body:The contents of the block.
        :type body: list(NodeNG) or None
        N)r)   ra   r   )rW   r)   ra   r   r   r   r   r   s  s    zExceptHandler.postinitc             C   s"   | j r| j jS | jr| jjS | jS )zPThe line on which the beginning of this block ends.

        :type: int
        )ra   r   r)   rU   )rW   r   r   r   blockstart_tolineno  s
    z!ExceptHandler.blockstart_tolinenoc             C   s<   | j dks|dkrdS x | j  D ]}|j|kr"dS q"W dS )zCheck if this node handles any of the given exceptions.

        If ``exceptions`` is empty, this will default to ``True``.

        :param exceptions: The name of the exceptions to check for.
        :type exceptions: list(str)
        NTF)r)   r   ra   )rW   r   r   r   r   r   r#     s    
zExceptHandler.catch)NNN)rp   r   r   r   rc   _multi_line_block_fieldsr)   ra   r   r   r   r   r   rO  r#   r   r   r   r   r   F  s   

r   c               @   s*   e Zd ZdZdZdZdZdZdddZdS )ExeczClass representing the ``exec`` statement.

    >>> node = astroid.extract_node('exec "True"')
    >>> node
    <Exec l.1 at 0x7f0e8106c6d0>
    )r  globalsr   Nc             C   s   || _ || _|| _dS )aN  Do some setup after initialisation.

        :param expr: The expression to be executed.
        :type expr: NodeNG or None

        :param globals:The globals dictionary to execute with.
        :type globals: NodeNG or None

        :param locals: The locals dictionary to execute with.
        :type locals: NodeNG or None
        N)r  rR  r   )rW   r  rR  r   r   r   r   r     s    zExec.postinit)NNN)	rp   r   r   r   rc   r  rR  r   r   r   r   r   r   rQ    s   rQ  c               @   s"   e Zd ZdZdZdZdddZdS )ExtSlicea  Class representing an :class:`ast.ExtSlice` node.

    An :class:`ExtSlice` is a complex slice expression.

    >>> node = astroid.extract_node('l[1:3, 5]')
    >>> node
    <Subscript l.1 at 0x7f23b2e9e550>
    >>> node.slice
    <ExtSlice l.1 at 0x7f23b7b05ef0>
    )dimsNc             C   s
   || _ dS )zDo some setup after initialisation.

        :param dims: The simple dimensions that form the complete slice.
        :type dims: list(NodeNG) or None
        N)rT  )rW   rT  r   r   r   r     s    zExtSlice.postinit)N)rp   r   r   r   rc   rT  r   r   r   r   r   rS    s   
rS  c               @   sT   e Zd ZdZdZdZdZdZdZdZ	dZ
dZdddZdZejd	d
 Zdd ZdS )ForzClass representing an :class:`ast.For` node.

    >>> node = astroid.extract_node('for thing in things: print(thing)')
    >>> node
    <For l.1 at 0x7f23b2e8cf28>
    )r!  r\   r   r   )r  )r   r   Nc             C   s"   || _ || _|| _|| _|| _dS )a  Do some setup after initialisation.

        :param target: What the loop assigns to.
        :type target: NodeNG or None

        :param iter: What the loop iterates over.
        :type iter: NodeNG or None

        :param body: The contents of the body of the loop.
        :type body: list(NodeNG) or None

        :param orelse: The contents of the ``else`` block of the loop.
        :type orelse: list(NodeNG) or None
        N)r!  r\   r   r   r  )rW   r!  r\   r   r   r  r   r   r   r     s
    zFor.postinitTc             C   s   | j jS )zPThe line on which the beginning of this block ends.

        :type: int
        )r\   r   )rW   r   r   r   rO  0  s    zFor.blockstart_tolinenoc             c   s,   | j V  | jV  | jE d H  | jE d H  d S )N)r!  r\   r   r   )rW   r   r   r   r   8  s    zFor.get_children)NNNNN)rp   r   r   r   rc   r   rP  r!  r\   r   r   r  r   r   r   r   rO  r   r   r   r   r   rU    s   
rU  c               @   s   e Zd ZdZdS )AsyncFora  Class representing an :class:`ast.AsyncFor` node.

    An :class:`AsyncFor` is an asynchronous :class:`For` built with
    the ``async`` keyword.

    >>> node = astroid.extract_node('''
    async def func(things):
        async for thing in things:
            print(thing)
    ''')
    >>> node
    <AsyncFunctionDef.func l.2 at 0x7f23b2e416d8>
    >>> node.body[0]
    <AsyncFor l.3 at 0x7f23b2e417b8>
    N)rp   r   r   r   r   r   r   r   rV  @  s   rV  c               @   s*   e Zd ZdZdZdZdddZdd ZdS )	rS   a  Class representing an :class:`ast.Await` node.

    An :class:`Await` is the ``await`` keyword.

    >>> node = astroid.extract_node('''
    async def func(things):
        await other_func()
    ''')
    >>> node
    <AsyncFunctionDef.func l.2 at 0x7f23b2e41748>
    >>> node.body[0]
    <Expr l.3 at 0x7f23b2e419e8>
    >>> list(node.body[0].get_children())[0]
    <Await l.3 at 0x7f23b2e41a20>
    )r'   Nc             C   s
   || _ dS )zyDo some setup after initialisation.

        :param value: What to wait for.
        :type value: NodeNG or None
        N)r'   )rW   r'   r   r   r   r   j  s    zAwait.postinitc             c   s   | j V  d S )N)r'   )rW   r   r   r   r   r  s    zAwait.get_children)N)rp   r   r   r   rc   r'   r   r   r   r   r   r   rS   R  s
   
c                   s&   e Zd ZdZdZd fdd	Z  ZS )
ImportFromzClass representing an :class:`ast.ImportFrom` node.

    >>> node = astroid.extract_node('from my_package import my_module')
    >>> node
    <ImportFrom l.1 at 0x7f23b2e415c0>
    )modnamerf   levelr   Nc                s*   || _ || _|| _tt| ||| dS )a  
        :param fromname: The module that is being imported from.
        :type fromname: str or None

        :param names: What is being imported from the module.
        :type names: list(tuple(str, str or None))

        :param level: The level of relative import.
        :type level: int

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)rX  rf   rY  r   rW  rX   )rW   Zfromnamerf   rY  rU   rV   r   )r:   r   r   rX     s    		zImportFrom.__init__)r   NNN)rp   r   r   r   rr   rX   r   r   r   )r:   r   rW  v  s   rW  c                   s@   e Zd ZdZdZdZdZd fdd	ZdddZd	d
 Z	  Z
S )	Attributez2Class representing an :class:`ast.Attribute` node.)r  )rb   Nc                s   || _ tt| ||| dS )a  
        :param attrname: The name of the attribute.
        :type attrname: str or None

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)rb   r   rZ  rX   )rW   rb   rU   rV   r   )r:   r   r   rX     s    zAttribute.__init__c             C   s
   || _ dS )zDo some setup after initialisation.

        :param expr: The name that this node represents.
        :type expr: Name or None
        N)r  )rW   r  r   r   r   r     s    zAttribute.postinitc             c   s   | j V  d S )N)r  )rW   r   r   r   r     s    zAttribute.get_children)NNNN)N)rp   r   r   r   rc   rr   r  rX   r   r   r   r   r   )r:   r   rZ    s   
rZ  c                   s.   e Zd ZdZdZd fdd	Zdd Z  ZS )	GlobalzClass representing an :class:`ast.Global` node.

    >>> node = astroid.extract_node('global a_global')
    >>> node
    <Global l.1 at 0x7f23b2e9de10>
    )rf   Nc                s   || _ tt| ||| dS )a  
        :param names: The names being declared as global.
        :type names: list(str)

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)rf   r   r[  rX   )rW   rf   rU   rV   r   )r:   r   r   rX     s    zGlobal.__init__c             C   s   |S )Nr   )rW   r   ra   r   r   r   r     s    zGlobal._infer_name)NNN)rp   r   r   r   rr   rX   r   r   r   r   )r:   r   r[    s   r[  c               @   sT   e Zd ZdZdZdZdZdZdZdddZ	e
jdd Zd	d
 Zdd Zdd ZdS )r    zClass representing an :class:`ast.If` node.

    >>> node = astroid.extract_node('if condition: print(True)')
    >>> node
    <If l.1 at 0x7f23b2e9dd30>
    )r  r   r   )r   r   Nc             C   s   || _ || _|| _dS )aN  Do some setup after initialisation.

        :param test: The condition that the statement tests.
        :type test: NodeNG or None

        :param body: The contents of the block.
        :type body: list(NodeNG) or None

        :param orelse: The contents of the ``else`` block.
        :type orelse: list(NodeNG) or None
        N)r  r   r   )rW   r  r   r   r   r   r   r   !  s    zIf.postinitc             C   s   | j jS )zPThe line on which the beginning of this block ends.

        :type: int
        )r  r   )rW   r   r   r   rO  1  s    zIf.blockstart_tolinenoc             C   sT   || j d jkr||fS || j d jkr8|| j d jfS | || j| j d jd S )a8  Get a range from the given line number to where this node ends.

        :param lineno: The line number to start the range at.
        :type lineno: int

        :returns: The range of line numbers that this node belongs to,
            starting at the given line number.
        :rtype: tuple(int, int)
        r   r   r   )r   r   r   _elsed_block_ranger   )rW   rU   r   r   r   r   9  s
    
zIf.block_rangec             c   s$   | j V  | jE d H  | jE d H  d S )N)r  r   r   )rW   r   r   r   r   I  s    zIf.get_childrenc             C   s   t | jdkot| jd tS )Nr   r   )rq   r   r   r    )rW   r   r   r   has_elif_blockO  s    zIf.has_elif_block)NNN)rp   r   r   r   rc   rP  r  r   r   r   r   r   rO  r   r   r]  r   r   r   r   r      s   
r    c               @   s:   e Zd ZdZdZdZdZdZd
ddZdd Z	dd	 Z
dS )rD   zClass representing an :class:`ast.IfExp` node.

    >>> node = astroid.extract_node('value if condition else other')
    >>> node
    <IfExp l.1 at 0x7f23b2e9dbe0>
    )r  r   r   Nc             C   s   || _ || _|| _dS )aN  Do some setup after initialisation.

        :param test: The condition that the statement tests.
        :type test: NodeNG or None

        :param body: The contents of the block.
        :type body: list(NodeNG) or None

        :param orelse: The contents of the ``else`` block.
        :type orelse: list(NodeNG) or None
        N)r  r   r   )rW   r  r   r   r   r   r   r   l  s    zIfExp.postinitc             c   s   | j V  | jV  | jV  d S )N)r  r   r   )rW   r   r   r   r   |  s    zIfExp.get_childrenc             C   s   dS )NFr   )rW   r   r   r   r     s    zIfExp.op_left_associative)NNN)rp   r   r   r   rc   r  r   r   r   r   r   r   r   r   r   rD   S  s   
c                   s&   e Zd ZdZdZd fdd	Z  ZS )ImportzClass representing an :class:`ast.Import` node.

    >>> node = astroid.extract_node('import astroid')
    >>> node
    <Import l.1 at 0x7f23b2e4e5c0>
    )rf   Nc                s   || _ tt| ||| dS )a  
        :param names: The names being imported.
        :type names: list(tuple(str, str or None)) or None

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)rf   r   r^  rX   )rW   rf   rU   rV   r   )r:   r   r   rX     s    	zImport.__init__)NNNN)rp   r   r   r   rr   rX   r   r   r   )r:   r   r^    s   r^  c               @   s*   e Zd ZdZdZdZdddZdd ZdS )	IndexzClass representing an :class:`ast.Index` node.

    An :class:`Index` is a simple subscript.

    >>> node = astroid.extract_node('things[1]')
    >>> node
    <Subscript l.1 at 0x7f23b2e9e2b0>
    >>> node.slice
    <Index l.1 at 0x7f23b2e9e6a0>
    )r'   Nc             C   s
   || _ dS )zDo some setup after initialisation.

        :param value: The value to subscript with.
        :type value: NodeNG or None
        N)r'   )rW   r'   r   r   r   r     s    zIndex.postinitc             c   s   | j V  d S )N)r'   )rW   r   r   r   r     s    zIndex.get_children)N)rp   r   r   r   rc   r'   r   r   r   r   r   r   r_    s
   

r_  c                   s@   e Zd ZdZdZdZdZd fdd	ZdddZd	d
 Z	  Z
S )KeywordzClass representing an :class:`ast.keyword` node.

    >>> node = astroid.extract_node('function(a_kwarg=True)')
    >>> node
    <Call l.1 at 0x7f23b2e9e320>
    >>> node.keywords
    [<Keyword l.1 at 0x7f23b2e9e9b0>]
    )r'   )r  Nc                s   || _ tt| ||| dS )a  
        :param arg: The argument being assigned to.
        :type arg: Name or None

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)r  r   r`  rX   )rW   r  rU   rV   r   )r:   r   r   rX     s    zKeyword.__init__c             C   s
   || _ dS )zDo some setup after initialisation.

        :param value: The value being assigned to the ketword argument.
        :type value: NodeNG or None
        N)r'   )rW   r'   r   r   r   r     s    zKeyword.postinitc             c   s   | j V  d S )N)r'   )rW   r   r   r   r     s    zKeyword.get_children)NNNN)N)rp   r   r   r   rc   rr   r'   rX   r   r   r   r   r   )r:   r   r`    s   
r`  c                   s8   e Zd ZdZdZd
 fdd	Zdd Zddd	Z  ZS )r   zClass representing an :class:`ast.List` node.

    >>> node = astroid.extract_node('[1, 2, 3]')
    >>> node
    <List.list l.1 at 0x7f23b2e9e128>
    )ctxNc                s   || _ tt| ||| dS )a  
        :param ctx: Whether the list is assigned to or loaded from.
        :type ctx: Context or None

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)ra  r   r   rX   )rW   ra  rU   rV   r   )r:   r   r   rX   
  s    zList.__init__c             C   s   dt  S )zyGet the name of the type that this node represents.

        :returns: The name of the type.
        :rtype: str
        z%s.list)rI  )rW   r   r   r   r   !  s    zList.pytypec             C   s   t | | j||dS )zGet an item from this node.

        :param index: The node to use as a subscript index.
        :type index: Const or Slice
        )r   )r@   r   )rW   r,   r   r   r   r   r>  )  s    zList.getitem)NNNN)N)	rp   r   r   r   rr   rX   r   r>  r   r   r   )r:   r   r      s
   r   c                   s.   e Zd ZdZdZd fdd	Zdd Z  ZS )	Nonlocala	  Class representing an :class:`ast.Nonlocal` node.

    >>> node = astroid.extract_node('''
    def function():
        nonlocal var
    ''')
    >>> node
    <FunctionDef.function l.2 at 0x7f23b2e9e208>
    >>> node.body[0]
    <Nonlocal l.3 at 0x7f23b2e9e908>
    )rf   Nc                s   || _ tt| ||| dS )a  
        :param names: The names being declared as not local.
        :type names: list(str)

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)rf   r   rb  rX   )rW   rf   rU   rV   r   )r:   r   r   rX   A  s    zNonlocal.__init__c             C   s   |S )Nr   )rW   r   ra   r   r   r   r   X  s    zNonlocal._infer_name)NNN)rp   r   r   r   rr   rX   r   r   r   r   )r:   r   rb  2  s   rb  c               @   s   e Zd ZdZdS )PasszClass representing an :class:`ast.Pass` node.

    >>> node = astroid.extract_node('pass')
    >>> node
    <Pass l.1 at 0x7f23b2e9e748>
    N)rp   r   r   r   r   r   r   r   rc  \  s   rc  c                   s8   e Zd ZdZdZdZdZd fdd	Zd	ddZ  Z	S )
PrintzClass representing an :class:`ast.Print` node.

    >>> node = astroid.extract_node('print "A message"')
    >>> node
    <Print l.1 at 0x7f0e8101d290>
    )destr  Nc                s   || _ tt| ||| dS )a  
        :param nl: Whether to print a new line.
        :type nl: bool or None

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)nlr   rd  rX   )rW   rf  rU   rV   r   )r:   r   r   rX   y  s    zPrint.__init__c             C   s   || _ || _dS )zDo some setup after initialisation.

        :param dest: Where to print to.
        :type dest: NodeNG or None

        :param values: What to print.
        :type values: list(NodeNG) or None
        N)re  r  )rW   re  r  r   r   r   r     s    	zPrint.postinit)NNNN)NN)
rp   r   r   r   rc   re  r  rX   r   r   r   r   )r:   r   rd  e  s   rd  c               @   s6   e Zd ZdZdZdZdZd
ddZdd Zdd	 Z	dS )RaisezClass representing an :class:`ast.Raise` node.

    >>> node = astroid.extract_node('raise RuntimeError("Something bad happened!")')
    >>> node
    <Raise l.1 at 0x7f23b2e9e828>
    N)r?   causec             C   s   || _ || _dS )zDo some setup after initialisation.

        :param exc: What is being raised.
        :type exc: NodeNG or None

        :param cause: The exception being used to raise this one.
        :type cause: NodeNG or None
        N)r?   rh  )rW   r?   rh  r   r   r   r     s    	zRaise.postinitc             C   s0   | j s
dS x | j  D ]}|jdkrdS qW dS )zCheck if this node raises a :class:`NotImplementedError`.

        :returns: True if this node raises a :class:`NotImplementedError`,
            False otherwise.
        :rtype: bool
        Fr$  T)r?   r   ra   )rW   ra   r   r   r   raises_not_implemented  s    
zRaise.raises_not_implementedc             c   s(   | j d k	r| j V  | jd k	r$| jV  d S )N)r?   rh  )rW   r   r   r   r     s    

zRaise.get_children)NN)
rp   r   r   r   r?   rc   rh  r   ri  r   r   r   r   r   rg    s   
rg  c               @   s:   e Zd ZdZdZdZdddZdd Zdd	 Zd
d Z	dS )ReturnzClass representing an :class:`ast.Return` node.

    >>> node = astroid.extract_node('return True')
    >>> node
    <Return l.1 at 0x7f23b8211908>
    )r'   Nc             C   s
   || _ dS )zDo some setup after initialisation.

        :param value: The value being returned.
        :type value: NodeNG or None
        N)r'   )rW   r'   r   r   r   r     s    zReturn.postinitc             c   s   | j d k	r| j V  d S )N)r'   )rW   r   r   r   r     s    
zReturn.get_childrenc             C   s   t | jtS )N)r   r'   r   )rW   r   r   r   is_tuple_return  s    zReturn.is_tuple_returnc             c   s
   | V  d S )Nr   )rW   r   r   r   r     s    z'Return._get_return_nodes_skip_functions)N)
rp   r   r   r   rc   r'   r   r   rk  r   r   r   r   r   rj    s   
rj  c               @   s   e Zd ZdZdd ZdS )SetzClass representing an :class:`ast.Set` node.

    >>> node = astroid.extract_node('{1, 2, 3}')
    >>> node
    <Set.set l.1 at 0x7f23b2e71d68>
    c             C   s   dt  S )zyGet the name of the type that this node represents.

        :returns: The name of the type.
        :rtype: str
        z%s.set)rI  )rW   r   r   r   r     s    z
Set.pytypeN)rp   r   r   r   r   r   r   r   r   rl    s   rl  c               @   sd   e Zd ZdZdZdZdZdZdddZdd Z	e
jdd	 Zd
d ZdddZdddZdd ZdS )r9   zClass representing an :class:`ast.Slice` node.

    >>> node = astroid.extract_node('things[1:3]')
    >>> node
    <Subscript l.1 at 0x7f23b2e71f60>
    >>> node.slice
    <Slice l.1 at 0x7f23b2e71e80>
    )r2   r3   r4   Nc             C   s   || _ || _|| _dS )a:  Do some setup after initialisation.

        :param lower: The lower index in the slice.
        :value lower: NodeNG or None

        :param upper: The upper index in the slice.
        :value upper: NodeNG or None

        :param step: The step to take between index.
        :param step: NodeNG or None
        N)r2   r3   r4   )rW   r2   r3   r4   r   r   r   r   !  s    zSlice.postinitc             C   s   |st |}| |_|S |S )z7Wrap the empty attributes of the Slice in a Const node.)r   r   )rW   r   Zconstr   r   r   _wrap_attribute1  s
    zSlice._wrap_attributec             C   s   t j}|dd S )Nr6   r   )r]   Zbuiltins_modulere   )rW   builtinsr   r   r   r@  9  s    zSlice._proxiedc             C   s   dt  S )zyGet the name of the type that this node represents.

        :returns: The name of the type.
        :rtype: str
        z%s.slice)rI  )rW   r   r   r   r   >  s    zSlice.pytypec             c   s`   |dkr|  | jV  nD|dkr0|  | jV  n,|dkrH|  | jV  n| j||dE dH  dS )zInfer the possible values of the given attribute on the slice.

        :param attrname: The name of the attribute to infer.
        :type attrname: str

        :returns: The inferred possible values.
        :rtype: iterable(NodeNG)
        startstopr4   )r   N)rm  r2   r3   r4   re   )rW   rb   r   r   r   r   igetattrF  s    	zSlice.igetattrc             C   s   | j ||S )N)r@  re   )rW   rb   r   r   r   r   re   X  s    zSlice.getattrc             c   s:   | j d k	r| j V  | jd k	r$| jV  | jd k	r6| jV  d S )N)r2   r3   r4   )rW   r   r   r   r   [  s    


zSlice.get_children)NNN)N)N)rp   r   r   r   rc   r2   r3   r4   r   rm  r   r   r@  r   rq  re   r   r   r   r   r   r9     s   


r9   c                   s@   e Zd ZdZdZdZdZd fdd	ZdddZd	d
 Z	  Z
S )r2  zClass representing an :class:`ast.Starred` node.

    >>> node = astroid.extract_node('*args')
    >>> node
    <Starred l.1 at 0x7f23b2e41978>
    )r'   )ra  Nc                s    || _ tt| j|||d dS )a  
        :param ctx: Whether the list is assigned to or loaded from.
        :type ctx: Context or None

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        )rU   rV   r   N)ra  r   r2  rX   )rW   ra  rU   rV   r   )r:   r   r   rX   v  s    
zStarred.__init__c             C   s
   || _ dS )zDo some setup after initialisation.

        :param value: What is being unpacked.
        :type value: NodeNG or None
        N)r'   )rW   r'   r   r   r   r     s    zStarred.postinitc             c   s   | j V  d S )N)r'   )rW   r   r   r   r     s    zStarred.get_children)NNNN)N)rp   r   r   r   rc   rr   r'   rX   r   r   r   r   r   )r:   r   r2  f  s   
r2  c                   sD   e Zd ZdZdZdZdZdZd fdd	ZdddZ	d	d
 Z
  ZS )	SubscriptzClass representing an :class:`ast.Subscript` node.

    >>> node = astroid.extract_node('things[1:3]')
    >>> node
    <Subscript l.1 at 0x7f23b2e71f60>
    )r'   r6   )ra  Nc                s    || _ tt| j|||d dS )a  
        :param ctx: Whether the subscripted item is assigned to or loaded from.
        :type ctx: Context or None

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        )rU   rV   r   N)ra  r   rr  rX   )rW   ra  rU   rV   r   )r:   r   r   rX     s    
zSubscript.__init__c             C   s   || _ || _dS )zDo some setup after initialisation.

        :param value: What is being indexed.
        :type value: NodeNG or None

        :param slice: The slice being used to lookup.
        :type slice: NodeNG or None
        N)r'   r6   )rW   r'   r6   r   r   r   r     s    	zSubscript.postinitc             c   s   | j V  | jV  d S )N)r'   r6   )rW   r   r   r   r     s    zSubscript.get_children)NNNN)NN)rp   r   r   r   rc   rr   r'   r6   rX   r   r   r   r   r   )r:   r   rr    s   
rr  c               @   sF   e Zd ZdZdZdZdZdZdZdddZ	dd Z
dd	 Zd
d ZdS )r"   a  Class representing an :class:`ast.TryExcept` node.

    >>> node = astroid.extract_node('''
        try:
            do_something()
        except Exception as error:
            print("Error!")
        ''')
    >>> node
    <TryExcept l.2 at 0x7f23b2e9d908>
    )r   r   r   Nc             C   s   || _ || _|| _dS )al  Do some setup after initialisation.

        :param body: The contents of the block to catch exceptions from.
        :type body: list(NodeNG) or None

        :param handlers: The exception handlers.
        :type handlers: list(ExceptHandler) or None

        :param orelse: The contents of the ``else`` block.
        :type orelse: list(NodeNG) or None
        N)r   r   r   )rW   r   r   r   r   r   r   r     s    zTryExcept.postinitc             C   s   |S )Nr   )rW   r   ra   r   r   r   r   
  s    zTryExcept._infer_namec             C   s   d}xx| j D ]n}|jr*||jjkr*||fS |jd j|  krN|jd jkrbn n||jd jfS |dkr|jd jd }qW | || j|S )a8  Get a range from the given line number to where this node ends.

        :param lineno: The line number to start the range at.
        :type lineno: int

        :returns: The range of line numbers that this node belongs to,
            starting at the given line number.
        :rtype: tuple(int, int)
        Nr   r   r   )r   r)   r   r   r   r\  r   )rW   rU   ZlastZ	exhandlerr   r   r   r     s    
(zTryExcept.block_rangec             c   s0   | j E d H  | jpdE d H  | jp$dE d H  d S )Nr   )r   r   r   )rW   r   r   r   r   !  s    zTryExcept.get_children)NNN)rp   r   r   r   rc   rP  r   r   r   r   r   r   r   r   r   r   r   r"     s   
r"   c               @   s:   e Zd ZdZdZdZdZdZd
ddZdd Z	dd	 Z
dS )
TryFinallya  Class representing an :class:`ast.TryFinally` node.

    >>> node = astroid.extract_node('''
    try:
        do_something()
    except Exception as error:
        print("Error!")
    finally:
        print("Cleanup!")
    ''')
    >>> node
    <TryFinally l.2 at 0x7f23b2e41d68>
    )r   	finalbodyNc             C   s   || _ || _dS )a  Do some setup after initialisation.

        :param body: The try-except that the finally is attached to.
        :type body: list(TryExcept) or None

        :param finalbody: The contents of the ``finally`` block.
        :type finalbody: list(NodeNG) or None
        N)r   rt  )rW   r   rt  r   r   r   r   D  s    	zTryFinally.postinitc             C   sT   | j d }t|trF|j| jkrF|j|  kr8| jkrFn n
||S | || jS )a8  Get a range from the given line number to where this node ends.

        :param lineno: The line number to start the range at.
        :type lineno: int

        :returns: The range of line numbers that this node belongs to,
            starting at the given line number.
        :rtype: tuple(int, int)
        r   )r   r   r"   r   r   r   r\  rt  )rW   rU   r   r   r   r   r   P  s    



zTryFinally.block_rangec             c   s   | j E d H  | jE d H  d S )N)r   rt  )rW   r   r   r   r   d  s    zTryFinally.get_children)NN)rp   r   r   r   rc   rP  r   rt  r   r   r   r   r   r   r   rs  (  s   
rs  c                   s8   e Zd ZdZdZd
 fdd	Zdd Zddd	Z  ZS )r   zClass representing an :class:`ast.Tuple` node.

    >>> node = astroid.extract_node('(1, 2, 3)')
    >>> node
    <Tuple.tuple l.1 at 0x7f23b2e41780>
    )ra  Nc                s   || _ tt| ||| dS )a  
        :param ctx: Whether the tuple is assigned to or loaded from.
        :type ctx: Context or None

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)ra  r   r   rX   )rW   ra  rU   rV   r   )r:   r   r   rX   s  s    zTuple.__init__c             C   s   dt  S )zyGet the name of the type that this node represents.

        :returns: The name of the type.
        :rtype: str
        z%s.tuple)rI  )rW   r   r   r   r     s    zTuple.pytypec             C   s   t | | j||dS )zGet an item from this node.

        :param index: The node to use as a subscript index.
        :type index: Const or Slice
        )r   )r@   r   )rW   r,   r   r   r   r   r>    s    zTuple.getitem)NNNN)N)	rp   r   r   r   rr   rX   r   r>  r   r   r   )r:   r   r   i  s
   r   c                   s`   e Zd ZdZdZdZdZd fdd	ZdddZdd	d
Z	dddZ
dd Z fddZ  ZS )rR   zClass representing an :class:`ast.UnaryOp` node.

    >>> node = astroid.extract_node('-5')
    >>> node
    <UnaryOp l.1 at 0x7f23b2e4e198>
    )operand)rB   Nc                s   || _ tt| ||| dS )a  
        :param op: The operator.
        :type: str or None

        :param lineno: The line that this node appears on in the source code.
        :type lineno: int or None

        :param col_offset: The column that this node appears on in the
            source code.
        :type col_offset: int or None

        :param parent: The parent node in the syntax tree.
        :type parent: NodeNG or None
        N)rB   r   rR   rX   )rW   rB   rU   rV   r   )r:   r   r   rX     s    zUnaryOp.__init__c             C   s
   || _ dS )zDo some setup after initialisation.

        :param operand: What the unary operator is applied to.
        :type operand: NodeNG or None
        N)ru  )rW   ru  r   r   r   r     s    zUnaryOp.postinitc             C   s   t d S )N)r$  )rW   r   r   r   r   _infer_unaryop  s    zUnaryOp._infer_unaryopc             C   s6   y| j |d}dd |D S  tjk
r0   g S X dS )a%  Get a list of type errors which can occur during inference.

        Each TypeError is represented by a :class:`BadBinaryOperationMessage`,
        which holds the original exception.

        :returns: The list of possible type errors.
        :rtype: list(BadBinaryOperationMessage)
        )r   c             S   s   g | ]}t |tjr|qS r   )r   r   ZBadUnaryOperationMessage)r.   ry   r   r   r   r     s   z'UnaryOp.type_errors.<locals>.<listcomp>N)rv  r   r*   )rW   r   r'  r   r   r   r(    s    	zUnaryOp.type_errorsc             c   s   | j V  d S )N)ru  )rW   r   r   r   r     s    zUnaryOp.get_childrenc                s   | j dkrt| j  S t  S )NrG   )rB   r   r   r   )rW   )r:   r   r   r     s    

zUnaryOp.op_precedence)NNNN)N)N)N)rp   r   r   r   rc   rr   ru  rX   r   rv  r(  r   r   r   r   r   )r:   r   rR     s   
	

c               @   sL   e Zd ZdZdZdZdZdZdZdddZ	e
jdd Zd	d
 Zdd ZdS )WhilezClass representing an :class:`ast.While` node.

    >>> node = astroid.extract_node('''
    while condition():
        print("True")
    ''')
    >>> node
    <While l.2 at 0x7f23b2e4e390>
    )r  r   r   )r   r   Nc             C   s   || _ || _|| _dS )aH  Do some setup after initialisation.

        :param test: The condition that the loop tests.
        :type test: NodeNG or None

        :param body: The contents of the loop.
        :type body: list(NodeNG) or None

        :param orelse: The contents of the ``else`` block.
        :type orelse: list(NodeNG) or None
        N)r  r   r   )rW   r  r   r   r   r   r   r     s    zWhile.postinitc             C   s   | j jS )zPThe line on which the beginning of this block ends.

        :type: int
        )r  r   )rW   r   r   r   rO    s    zWhile.blockstart_tolinenoc             C   s   |  || jS )a8  Get a range from the given line number to where this node ends.

        :param lineno: The line number to start the range at.
        :type lineno: int

        :returns: The range of line numbers that this node belongs to,
            starting at the given line number.
        :rtype: tuple(int, int)
        )r\  r   )rW   rU   r   r   r   r      s    
zWhile.block_rangec             c   s$   | j V  | jE d H  | jE d H  d S )N)r  r   r   )rW   r   r   r   r   ,  s    zWhile.get_children)NNN)rp   r   r   r   rc   rP  r  r   r   r   r   r   rO  r   r   r   r   r   r   rw    s   	
rw  c               @   sH   e Zd ZdZdZdZdZdZdZdZ	dddZ
ejdd	 Zd
d ZdS )WithzClass representing an :class:`ast.With` node.

    >>> node = astroid.extract_node('''
    with open(file_path) as file_:
        print(file_.read())
    ''')
    >>> node
    <With l.2 at 0x7f23b2e4e710>
    )rF  r   )r  )r   Nc             C   s   || _ || _|| _dS )a9  Do some setup after initialisation.

        :param items: The pairs of context managers and the names
            they are assigned to.
        :type items: list(tuple(NodeNG, AssignName or None)) or None

        :param body: The contents of the ``with`` block.
        :type body: list(NodeNG) or None
        N)rF  r   r  )rW   rF  r   r  r   r   r   r   V  s    
zWith.postinitc             C   s   | j d d jS )zPThe line on which the beginning of this block ends.

        :type: int
        r   r   )rF  r   )rW   r   r   r   rO  d  s    zWith.blockstart_tolinenoc             c   s4   x"| j D ]\}}|V  |r|V  qW | jE dH  dS )zoGet the child nodes below this node.

        :returns: The children.
        :rtype: iterable(NodeNG)
        N)rF  r   )rW   r  varr   r   r   r   l  s
    
zWith.get_children)NNN)rp   r   r   r   rc   r   rP  rF  r   r  r   r   r   rO  r   r   r   r   r   rx  3  s   
rx  c               @   s   e Zd ZdZdS )	AsyncWithz7Asynchronous ``with`` built with the ``async`` keyword.N)rp   r   r   r   r   r   r   r   rz  y  s   rz  c               @   s2   e Zd ZdZdZdZd
ddZdd Zdd	 ZdS )YieldzClass representing an :class:`ast.Yield` node.

    >>> node = astroid.extract_node('yield True')
    >>> node
    <Yield l.1 at 0x7f23b2e4e5f8>
    )r'   Nc             C   s
   || _ dS )z{Do some setup after initialisation.

        :param value: The value to yield.
        :type value: NodeNG or None
        N)r'   )rW   r'   r   r   r   r     s    zYield.postinitc             c   s   | j d k	r| j V  d S )N)r'   )rW   r   r   r   r     s    
zYield.get_childrenc             c   s
   | V  d S )Nr   )rW   r   r   r   r     s    z#Yield._get_yield_nodes_skip_lambdas)N)	rp   r   r   r   rc   r'   r   r   r   r   r   r   r   r{  }  s   
r{  c               @   s   e Zd ZdZdS )	YieldFromz2Class representing an :class:`ast.YieldFrom` node.N)rp   r   r   r   r   r   r   r   r|    s   r|  c               @   s   e Zd ZdZdS )rJ  z>Represents the unpacking of dicts into dicts using :pep:`448`.N)rp   r   r   r   r   r   r   r   rJ    s   rJ  c               @   s2   e Zd ZdZdZdZdZdZdddZdd Z	dS )	FormattedValuea9  Class representing an :class:`ast.FormattedValue` node.

    Represents a :pep:`498` format string.

    >>> node = astroid.extract_node('f"Format {type_}"')
    >>> node
    <JoinedStr l.1 at 0x7f23b2e4ed30>
    >>> node.values
    [<Const.str l.1 at 0x7f23b2e4eda0>, <FormattedValue l.1 at 0x7f23b2e4edd8>]
    )r'   format_specNc             C   s   || _ || _|| _dS )at  Do some setup after initialisation.

        :param value: The value to be formatted into the string.
        :type value: NodeNG

        :param conversion: The type of formatting to be applied to the value.
        :type conversion: int or None

        :param format_spec: The formatting to be applied to the value.
        :type format_spec: JoinedStr or None
        N)r'   
conversionr~  )rW   r'   r  r~  r   r   r   r     s    zFormattedValue.postinitc             c   s   | j V  | jd k	r| jV  d S )N)r'   r~  )rW   r   r   r   r     s    
zFormattedValue.get_children)NN)
rp   r   r   r   rc   r'   r  r~  r   r   r   r   r   r   r}    s   
	
r}  c               @   s*   e Zd ZdZdZdZdddZdd ZdS )		JoinedStrzRepresents a list of string expressions to be joined.

    >>> node = astroid.extract_node('f"Format {type_}"')
    >>> node
    <JoinedStr l.1 at 0x7f23b2e4ed30>
    )r  Nc             C   s
   || _ dS )zDo some setup after initialisation.

        :param value: The string expressions to be joined.

        :type: list(FormattedValue or Const) or None
        N)r  )rW   r  r   r   r   r     s    zJoinedStr.postinitc             c   s   | j E d H  d S )N)r  )rW   r   r   r   r     s    zJoinedStr.get_children)N)rp   r   r   r   rc   r  r   r   r   r   r   r   r    s
   
	r  c               @   s&   e Zd ZdZd Zdd ZdddZdS )UnknownzThis node represents a node in a constructed AST where
    introspection is not possible.  At the moment, it's only used in
    the args attribute of FunctionDef nodes where function signature
    introspection failed.
    c             C   s   dS )Nr  r   )rW   r   r   r   r     s    zUnknown.qnameNc             k   s   t jV  dS )z4Inference on an Unknown node immediately terminates.N)r   r   )rW   r   r^   r   r   r   r     s    zUnknown.infer)N)rp   r   r   r   ra   r   r   r   r   r   r   r    s   r  c              C   s*   t tttttf} x| D ]}tt|< qW dS )z?update constant classes, so the keys of CONST_CLS can be reusedN)r   r(   floatcomplexr<  r=  r&   	CONST_CLS)ZklassesZklsr   r   r   _update_const_classes  s    
r  c             C   s   |  }| | |S )N)r   )r   r'   r>   r   r   r   _two_step_initialization!  s    
r  c             C   s    t |trt| }t| |S )N)r   r   r   rF  r  )r   r'   r   r   r   _dict_initialization'  s    
r  c             C   s   | |S )Nr   )r   r'   r   r   r   <lambda>2  s    r  c          	   C   sp   t | trtt | ttttfr&g }n| }yt| j }t	| }|||S  t
tfk
rj   t }| |_|S X dS )z)return an astroid node for a python valueN)r   rT   r   r   r   r   r   r  r:   _CONST_CLS_CONSTRUCTORSKeyErrorr9  rM  rN  )r'   r   Zinitializer_clsZinitializerr   r   r   r   r   6  s    

r   c             C   s,   | j }x |dk	r&t|trdS |j }qW dS )z9Return True if the given node is the child of a decoratorNTF)r   r   rB  )r   r   r   r   r   r   R  s    


r   )N)N)N)N)N)F)NN){r   r   rn  Zbuiltins_modr  rs   	functoolsr   r   r   Zastroidr   r   r   r   r   r   r	   r
   r   rp   rI  ZAstroidManagerr]   Zraise_if_nothing_inferredr   r%   rN  r+   r-   r8   r@   r  r   rT   r   ZParentAssignTypeMixinZInstanceABCMetar   r   ZNoChildrenMixinr   r   r   ZAssignTypeMixinr   r  r  r  r  r  r   r#  r)  r*  r.  r/  r0  rH   r6  r&   rA  rB  rC  rD  rE  rK  rL  rM  ZMultiLineBlockMixinr   rQ  rS  ZBlockRangeMixInrU  rV  rS   ZImportFromMixinrW  rZ  r[  r    rD   r^  r_  r`  r   rb  rc  rd  rg  rj  rl  r9   r2  rr  r"   rs  r   rR   rw  rx  rz  r{  r|  rJ  r}  r  r  r   r   r   r   r)   NotImplementedr  r  r  r  r  r   r   r   r   r   r   <module>   s"  
L


     ?#
O F
*
'/  

7)7>Y]8	E>e}	-5 $Y+
V$>.%L4%52*	86"`5@MA2PH
B: