
    ei                       d dl mZ d dlZd dlZd dlZd dlmZmZ d dlm	Z	 d dlm
Z d dlmZmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d d	lmZmZmZmZ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*m+Z+m,Z, ejZ                  dk\  rd dlm.Z. nd dl/m.Z. erd dlm0Z0  edd      Z1 edd      Z2 edd      Z3eded   eed   df   f   Z4 G d d      Z5y)    )annotationsN)	GeneratorIterator)cached_property)singledispatch)
TYPE_CHECKINGAnyClassVarLiteralTupleTypeTypeVarUnioncastoverload)util)InferenceContext)AstroidErrorInferenceErrorParentMissingErrorStatementMissingUseInferenceDefault)AstroidManagerAsStringVisitor)OP_PRECEDENCE)Position)InferenceErrorInfoInferenceResultInferFn)      )Self)nodes_NodesTNodeNG)bound_NodesT2_NodesT3.c                     e Zd ZU dZdZded<   	 dZded<   	 dZded<   	 dZded<   dZ	d	ed
<   	 dZ
d	ed<   	 dZd	ed<   	 dZded<   	 	 	 	 	 	 	 	 	 	 	 	 d>dZ	 d?	 	 	 	 	 d@dZdAdZdAdZdAdZdBdZdCdZdDdZdCdZdEdZdddFdZdd	 	 	 dGdZdHdZdIdZd Zd  Zd! Zd" ZedJd#       Z edJd$       Z!dJd%Z"dKd&Z#dLd'Z$e%	 dM	 	 	 	 	 dNd(       Z&e%	 dM	 	 	 	 	 dOd)       Z&e%	 dM	 	 	 	 	 dPd*       Z&e%	 dM	 	 	 	 	 dQd+       Z&	 d?	 	 	 	 	 dRd,Z&edSd-       Z'd. Z(d/ Z)d0 Z*d1 Z+d2 Z,	 d?	 	 	 	 	 dTd3Z-d4 Z.d5 Z/dEd6Z0dEd7Z1dEd8Z2dAd9Z3	 	 	 	 	 	 dU	 dAd:Z4d?dVd;Z5d< Z6dEd=Z7y)Wr&   zlA node of the new Abstract Syntax Tree (AST).

    This is the base class for all Astroid node classes.
    FzClassVar[bool]is_statementoptional_assignis_function	is_lambda zClassVar[tuple[str, ...]]_astroid_fields_other_fields_other_other_fieldsNzInferFn[Self] | None_explicit_inferencec               b    || _         	 || _        	 || _        	 || _        	 || _        	 d | _        y N)lineno
col_offsetparent
end_linenoend_col_offsetposition)selfr6   r7   r8   r9   r:   s         7/usr/lib/python3/dist-packages/astroid/nodes/node_ng.py__init__zNodeNG.__init__\   sG     D$F1$D,	
 *.	    c              +  2  K   |t               }n|j                  j                  | |      }| j                  4	  | j                  | |fi |D ]  }|xj                  dz  c_        |  y| |j                  |j                  |j                  f}||j                  v r|j                  |   E d{    yg }t               j                  }t         | j                  dd|i|      D ]  \  }}||k\  s|j                  |j                  kD  r3|j                  t         j"                         t         j"                    n,|j                  |       | |xj                  dz  c_         t%        |      |j                  |<   y# t
        $ r Y %w xY w7 w)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   contextr/   )r   extra_contextgetr3   nodes_inferredr   
lookupnamecallcontext	boundnodeinferredr   max_inferable_values	enumerate_infermax_inferredappendr   Uninferabletuple)r<   rB   kwargsresultkeyresultslimitis           r=   inferzNodeNG.infer~   s     ?&(G++//g>G##/
6d66  !F
 **a/* L!  W'')<)<g>O>OP'"""'',,,  55";4;;#Iw#I&#IJ 	(IAvEzg44w7K7KKt//0&&&NN6"L""a'"	( !&g3 ' 
 -s6   6F2F +AF0F1CF	FFFFc                f     t         fddD              rt         dd      xs t         dd      S y)zyGet a name for nice representation.

        This is either :attr:`name`, :attr:`attrname`, or the empty string.
        c              3  :   K   | ]  }|j                   v  y wr5   )r0   ).0namer<   s     r=   	<genexpr>z#NodeNG.repr_name.<locals>.<genexpr>   s     QDt4///Qs   )r[   attrnamer[    r]   )allgetattrr<   s   `r=   	repr_namezNodeNG.repr_name   s4    
 Q<PQQ4,Mj"0MMr?   c                H   | j                         }t        |       j                  }|rd}t        |      t        |      z   dz   }nd}t        |      dz   }g }| j                  | j
                  z   D ]  }t        | |d      }dt        |      z
  |z
  }t        j                  |d|      j                  d      }	|	d	   g}
|	dd  D ]  }|
j                  d
|z  |z           |j                  | ddj                  |
               |||dd
|z  z   j                  |      dz  S )Nz%(cname)s.%(rname)s(%(fields)s)   z%(cname)s(%(fields)s)rA   UnknownP   )indentwidthTr    =r^   ,
)cnamernamefields)rb   type__name__lenr1   r0   r`   pprintpformat
splitlinesrN   join)r<   rm   rl   string	alignmentrR   fieldvaluerh   linesinnerlines               r=   __str__zNodeNG.__str__   s6    T
##6FE
SZ/!3I,FE
QI''$*>*>> 	7ED%3EUOi/ENN5%@KKDQE1XJEab	 5S9_t345MMUG1RWWU^$456	7 sY.44V<
 
 	
r?   c                    | j                         }	 | j                  }|rd}nd}|t        |       j                  ||t        |       dz  S # t        $ r d}Y :w xY w)Nr   z.<%(cname)s.%(rname)s l.%(lineno)s at 0x%(id)x>z$<%(cname)s l.%(lineno)s at 0x%(id)x>)rl   rm   r6   id)rb   
fromlinenoAttributeErrorro   rp   r   )r<   rm   r6   rv   s       r=   __repr__zNodeNG.__repr__   sm     	__F EF;F$Z((T(	
 
 	
  	F	s   A AAc                t    t        |d| j                  j                  j                         z         } ||       S )z(Visit this node using the given visitor.visit_)r`   	__class__rp   lower)r<   visitorfuncs      r=   acceptzNodeNG.accept   s0    w4>>+B+B+H+H+J JKDzr?   c              #     K   | j                   D ]6  }t        | |      }|t        |t        t        f      r|E d{    3| 8 dE d{    y7 7 w)z$Get the child nodes below this node.Nr/   r0   r`   
isinstancelistrP   r<   rx   attrs      r=   get_childrenzNodeNG.get_children   s]     )) 	E4'D|$u.
	    	s!   :AAAAAAc                    | j                   ddd   D ]1  }t        | |      }|st        |t        t        f      r|d   c S |c S  y)z1An optimized version of list(get_children())[-1].Nr   r   s      r=   
last_childzNodeNG.last_child   sS    ))$B$/ 	E4'D$u.BxK	 r?   c              #  P   K   | j                   }|| |j                   }|yyw)z7Yield parent, grandparent, etc until there are no more.Nr8   r<   r8   s     r=   node_ancestorszNodeNG.node_ancestors  s+      L]]F  s   !&&c                H     t         fd|j                         D              S )zCheck 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: Whether this node is the parent of the given node.
        c              3  &   K   | ]  }|u  
 y wr5   r/   )rZ   r8   r<   s     r=   r\   z#NodeNG.parent_of.<locals>.<genexpr>  s     Ff46>Fs   )anyr   r<   nodes   ` r=   	parent_ofzNodeNG.parent_of  s     F0C0C0EFFFr?   futurec                   |t        j                  dt        d       | j                  rt	        d|       S | j
                  st        |       | j
                  j                         S )zThe first parent node, including self, marked as statement node.

        :raises StatementMissing: If self has no parent attribute.
        .The future arg will be removed in astroid 4.0.rd   
stacklevelnodes.Statementtarget)warningswarnDeprecationWarningr+   r   r8   r   	statementr<   r   s     r=   r   zNodeNG.statement  s]    
 MM@"
 )400{{"$//{{$$&&r?   c                   |t        j                  dt        d       | j                  t	        |       | j                  j                  |      S )a
  The first parent frame node.

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

        :returns: The first parent frame node.
        :raises ParentMissingError: If self has no parent attribute.
        r   rd   r   r   r   )r   r   r   r8   r   framer   s     r=   r   zNodeNG.frame*  sN     MM@"
 ;;$D11{{   //r?   c                f    | j                   st        |       | j                   j                         S )zThe first parent node defining a new scope.

        These can be Module, FunctionDef, ClassDef, Lambda, or GeneratorExp nodes.

        :returns: The first parent scope node.
        r   )r8   r   scopera   s    r=   r   zNodeNG.scope?  s)     {{$D11{{  ""r?   c                p    | j                   x}s| S |j                   r|j                   }|j                   r|S )zSReturn the root node of the syntax tree.

        :returns: The root node.
        r   r   s     r=   rootzNodeNG.rootJ  s6    
 ++%%Kmm]]F mmr?   c                    | j                   D ]6  }t        | |      }||u r|gc S t        |t        t        f      s/||v s4|c S  d}t        |t        |      t        |       fz        )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.
        "Could not find %s in %s's childrenr0   r`   r   rP   r   r   reprr<   childrx   node_or_sequencemsgs        r=   child_sequencezNodeNG.child_sequenceV  s{     )) 		(E&tU35(()) +eT];--''		( 33$u+tDz!::;;r?   c                    | j                   D ]9  }t        | |      }||u r||fc S t        |t        t        f      s0||v s5||fc S  d}t        |t        |      t        |       fz        )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.
        r   r   r   s        r=   locate_childzNodeNG.locate_childp  s     )) 		/E&tU3((e|#+eT];--...		/ 33$u+tDz!::;;r?   c                6    | j                   j                         S )z|The next sibling statement node.

        :returns: The next sibling statement node.
        :rtype: NodeNG or None
        )r8   next_siblingra   s    r=   r   zNodeNG.next_sibling  s     {{''))r?   c                6    | j                   j                         S )zThe previous sibling statement.

        :returns: The previous sibling statement node.
        :rtype: NodeNG or None
        )r8   previous_siblingra   s    r=   r   zNodeNG.previous_sibling  s     {{++--r?   c                R    | j                   | j                         S | j                   S )zThe first line that this node appears on in the source code.

        Can also return 0 if the line can not be determined.
        )r6   _fixed_source_linera   s    r=   r   zNodeNG.fromlineno  s'     ;;**,,{{r?   c                    | j                   | j                   S | j                  sd}n| j                         }|| j                  S |j                  S )zThe last line that this node appears on in the source code.

        Can also return 0 if the line can not be determined.
        N)r9   r0   r   r   tolineno)r<   r   s     r=   r   zNodeNG.tolineno  sN     ??&??"##J*J??""""r?   c                    | j                   }| }	 |(t        |j                               }|j                   }|(|xs dS # t        $ r0 | j                  }|r||j                   }|j                  }|r|Y >w xY w)zAttempt to find the line that this node appears on.

        We need this method since not all nodes have :attr:`lineno` set.
        Will return 0 if the line number can not be determined.
        r   )r6   nextr   StopIterationr8   )r<   r|   _noder8   s       r=   r   zNodeNG._fixed_source_line  s     {{	',U//12|| , yq  	'[[FT\}} T\	's   )A   5A98A9c                    || j                   fS )zGet a range from the given line number to where this node ends.

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

        :returns: The range of line numbers that this node belongs to,
            starting at the given line number.
        )r   )r<   r6   s     r=   block_rangezNodeNG.block_range  s     t}}$$r?   c                X    | j                   sJ | j                   j                  ||       y)a$  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.

        :param stmt: The statement that defines the given name.
        N)r8   	set_local)r<   r[   stmts      r=   r   zNodeNG.set_local  s$     {{{dD)r?   c                     y r5   r/   r<   klass
skip_klasss      r=   nodes_of_classzNodeNG.nodes_of_class       	r?   c                     y r5   r/   r   s      r=   r   zNodeNG.nodes_of_class  r   r?   c                     y r5   r/   r   s      r=   r   zNodeNG.nodes_of_class  r   r?   c                     y r5   r/   r   s      r=   r   zNodeNG.nodes_of_class  r   r?   c              #    K   t        | |      r|  |0| j                         D ]  }|j                  ||      E d{     y| j                         D ])  }t        ||      r|j                  ||      E d{    + y7 D7 	w)a+  Get the nodes (including this one or below) of the given types.

        :param klass: The types of node to search for.

        :param skip_klass: The types of node to ignore. This is useful to ignore
            subclasses of :attr:`klass`.

        :returns: The node of the given types.
        N)r   r   r   )r<   r   r   
child_nodes       r=   r   zNodeNG.nodes_of_class  s     & dE"J"//1 H
%44UJGGGH ++- 	DJ*j1!00
CCC	D	 H Ds!   ;BB<B:B;BBc                    g S r5   r/   ra   s    r=   _assign_nodes_in_scopezNodeNG._assign_nodes_in_scope'  s    	r?   c              #  j   K   | j                         D ]  }|j                         E d {     y 7 wr5   )r   _get_name_nodes)r<   r   s     r=   r   zNodeNG._get_name_nodes+  s3     ++- 	4J!11333	43s   '313c              #  $   K   dE d {    y 7 wNr/   r/   ra   s    r=    _get_return_nodes_skip_functionsz'NodeNG._get_return_nodes_skip_functions/          c              #  $   K   dE d {    y 7 wr   r/   ra   s    r=   _get_yield_nodes_skip_functionsz&NodeNG._get_yield_nodes_skip_functions2  r   r   c              #  $   K   dE d {    y 7 wr   r/   ra   s    r=   _get_yield_nodes_skip_lambdasz$NodeNG._get_yield_nodes_skip_lambdas5  r   r   c                     y r5   r/   )r<   r   r[   s      r=   _infer_namezNodeNG._infer_name8  s    r?   c                    t        d| |      )z4We don't know how to resolve a statement by default.z#No inference function for {node!r}.)r   rB   )r   )r<   rB   rQ   s      r=   rL   zNodeNG._infer<  s    
 1g
 	
r?   c                4    t        | j                               S )zGet a list of the inferred values.

        .. seealso:: :ref:`inference`

        :returns: The inferred values.
        :rtype: list
        )r   rW   ra   s    r=   rI   zNodeNG.inferredE  s     DJJL!!r?   c                    | 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/   ra   s    r=   instantiate_classzNodeNG.instantiate_classO  s	     r?   c                     y)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/   r   s     r=   has_basezNodeNG.has_base[  s     r?   c                     y)zWhether this node defines something that is callable.

        :returns: Whether this defines something that is callable.
        Fr/   ra   s    r=   callablezNodeNG.callabled  s    
 r?   c                     y)NFr/   )r<   ry   s     r=   eqz	NodeNG.eqk  s    r?   c                "     t               |       S )z.Get the source code that this node represents.r   ra   s    r=   	as_stringzNodeNG.as_stringn  s      &&r?   c                ,  
 t         dfd	       

j                  t              
j                  t              d
fd	              }
j                  t              d
fd	       }g }	 
| |	t                      dj                  |	      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
        r^   c           	        t        j                  | t        t        |      z
  d            j	                  d      }|j                  |d          |j                  |dd D cg c]  }||z   	 c}       t        |      dk7  S c c}w )zOutputs a representation of a non-tuple/list, non-node that's
            contained within an AST, including strings.
            rA   )rh   Tr   N)rr   rs   maxrq   rt   rN   extend)r   rR   done
cur_indentdepthrz   r|   	max_widths          r=   
_repr_treez$NodeNG.repr_tree.<locals>._repr_tree  s}    
 NNC	C
O ;Q?j  MM%(#MMqrC:,CDu:?" Ds   $Bc                @   |z  }|j                  d       | sd}nt        |       dk(  r | d   ||||      }nt        |       dk(  rY | d   ||||      }|s|j                  d       n"|j                  d       |j                  |        | d   ||||      xs |}nk|j                  d       |j                  |       | d	d
 D ]0  } |||||       |j                  d       |j                  |       2  | d
   ||||       d}|j                  d       |S )z_Outputs a representation of a sequence that's contained within an
            AST.
            [FrA   r   rd   z, rk   
Nr   T])rN   rq   )	r   rR   r   r   r   brokenr   r   rg   s	          r=   	_repr_seqz#NodeNG.repr_tree.<locals>._repr_seq  s)    & JMM#Ta#DGVT:uMTa#DGVT:uMMM$'MM%(MM*-#DGVT:uMWQWd#j)!#2Y .EufdJFMM%(MM*-. 48VT:uEMM#Mr?   c           	     |   | |v r7|j                  dt        |       j                   dt        |        z          y|j	                  |        r|kD  r|j                  d       y|dz  }|z  }
r5|j                  t        |       j                   dt        |       dd       n'|j                  t        |       j                   d	       g }r|j                  d
       |j                  | j                         |j                  | j                         	r|j                  | j                         |sd}nt        |      dk(  r1|j                  |d    d        t        | |d         ||||      }n|j                  d       |j                  |       |dd D ]T  }|dk(  r	|j                  | d        t        | |      ||||       |j                  d       |j                  |       V |j                  |d    d        t        | |d         ||||       d}|j                  d       |S )z4Outputs a strings representation of an astroid node.z<Recursion on z	 with id=Fz...rA   z<0xxz>(
()r6   r7   r   rj   r   Nr   docrk   T))rN   ro   rp   r   addr   r1   r0   r2   rq   r`   )r   rR   r   r   r   rn   r  rx   r   	ast_stateidsinclude_linenosrg   	max_depths           r=   
_repr_nodez$NodeNG.repr_tree.<locals>._repr_node  s     t|~d4j.A.A-B)BtH:VV HHTNUY.e$QJE& Jd!4!4 5SD!DIJd!4!4 5Q78F67MM$,,-MM$../d667V!1o.#D&),fdJ d#j)#CR[ .E~ MMUG1+.wtU3VT:uUMM%(MM*-. A./744fdJPUVMM#Mr?   )r^   rA   )_singledispatchregisterrP   r   r&   setru   )r<   r
  r  r	  rg   r  r   r  r  rR   r   s    ``````   @r=   	repr_treezNodeNG.repr_treer  s    L 
		# 
		# 
		U	#			T	"	 
# 
$	> 
		V	$/	 /	 
%/	b 4'wwvr?   c                "    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   rO   )r<   rB   s     r=   
bool_valuezNodeNG.bool_value  s    $ r?   c                p    t        j                  | j                  j                  t	        t                     S r5   )r   rD   r   rp   rq   ra   s    r=   op_precedencezNodeNG.op_precedence  s$      !8!8#m:LMMr?   c                     y)NTr/   ra   s    r=   op_left_associativezNodeNG.op_left_associative  s    r?   )r6   
int | Noner7   r  r8   NodeNG | Noner9   r  r:   r  returnNoner5   )rB   InferenceContext | NonerQ   r	   r  z&Generator[InferenceResult, None, None])r  str)r   r   r  r  )r  zIterator[NodeNG])r  r  )r  bool)r   Literal[None, True]r  r   )r   r  r  z@nodes.FunctionDef | nodes.Module | nodes.ClassDef | nodes.Lambda)r  znodes.LocalsDictNodeNG)r  znodes.Module)r  int)r6   r   r  ztuple[int, int])r[   r  r   r&   r  r  ).)r   ztype[_NodesT]r   
SkipKlassTr  Iterator[_NodesT])r   z$tuple[type[_NodesT], type[_NodesT2]]r   r!  r  z&Iterator[_NodesT] | Iterator[_NodesT2])r   z4tuple[type[_NodesT], type[_NodesT2], type[_NodesT3]]r   r!  r  ;Iterator[_NodesT] | Iterator[_NodesT2] | Iterator[_NodesT3])r   ztuple[type[_NodesT], ...]r   r!  r  r"  )r   ztype[_NodesT] | tuple[type[_NodesT], type[_NodesT2]] | tuple[type[_NodesT], type[_NodesT2], type[_NodesT3]] | tuple[type[_NodesT], ...]r   r!  r  r#  )r  zlist[nodes.Assign])rB   r  rQ   r	   r  z;Generator[InferenceResult, None, InferenceErrorInfo | None])FFFz   r   rf   )rB   r  )8rp   
__module____qualname____doc__r+   __annotations__r,   r-   r.   r0   r1   r2   r3   r>   rW   rb   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rL   rI   r   r   r   r   r   r  r  r  r  r/   r?   r=   r&   r&   :   s0   
 $)L.(2 	    #(K'1 %I~% 24O.3 02M,1:5727704-4     	    #  
 F 267.7AD7	/7r
4
$

	#G :> '$ 040,0	I0*	#
<4<:*.   # # &%*  "%  
	   "%3  
0	   "%C  
E	   "%(  
	  "&D(D D 
EDB  4
 26
.
AD
	D
"
' H 
HT (Nr?   )6
__future__r   rr   sysr   collections.abcr   r   	functoolsr   r   r  typingr   r	   r
   r   r   r   r   r   r   r   astroidr   astroid.contextr   astroid.exceptionsr   r   r   r   r   astroid.managerr   astroid.nodes.as_stringr   astroid.nodes.constr   astroid.nodes.utilsr   astroid.typingr   r   r    version_infor#   typing_extensionsr$   r%   r(   r)   r!  r&   r/   r?   r=   <module>r7     s   
 #  
  / % 7    ,  + 3 - ( G Gw&  )8
,:X.:X.4htH~s/B)CCD
\ \r?   