
    e                        d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
 ddlmZmZ ddlmZ ddlmZmZ erdd	lmZ  ed
      Z G d dej,                        Z G d de      Zy)z4This module contains mixin classes for scoped nodes.    )annotations)TYPE_CHECKINGTypeVaroverload)ParentMissingError)_filter_stmts)_base_nodesscoped_nodes)builtin_lookup)InferenceResultSuccessfulInferenceResult)nodes_Tc                      e Zd ZU dZded<   	 ddZddZ	 d	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 ddZddZ	e	Z
dd	Ze	 d	 	 	 	 	 dd
       Zedd       ZdddZddZd Zd Zd Zd Zd dZy)!LocalsDictNodeNGzthis class provides locals handling common to Module, FunctionDef
    and ClassDef nodes, including a dict like interface for direct access
    to locals information
    z dict[str, list[InferenceResult]]localsc                    | j                   | j                  S 	 | j                   j                         j                          d| j                   S # t        $ r | j                  cY S w xY w)zGet the 'qualified' name of the node.

        For example: module.name, module.class.name ...

        :returns: The qualified name.
        :rtype: str
        .)parentnameframeqnamer   selfs    B/usr/lib/python3/dist-packages/astroid/nodes/scoped_nodes/mixin.pyr   zLocalsDictNodeNG.qname!   sb     ;;99	kk'')//12!DII;??! 	99	s   6A A)(A)c                    | 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   s    r   scopezLocalsDictNodeNG.scope1   s	         c                    t         )a  Lookup where the given variable is assigned.

        :param node: The node to look for assignments up to.
            Any assignments after the given node are ignored.

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

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

        :returns: This 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).
        )NotImplementedError)r   noder   offsets       r   scope_lookupzLocalsDictNodeNG.scope_lookup9   s
      "!r   c                   	 t        || j                  |   | |      }|r| |fS | j                  xr | j                  j	                         }|Wt        |t        j                        s|j                  ||      S |j                  xr |j                  j	                         }|Wt        |      S # t        $ r d}Y w xY w)z+XXX method for interfacing the scope lookupr   )
r   r   KeyErrorr   r   
isinstancer
   ClassDefr$   r   )r   r"   r   r#   stmtspscopes         r   _scope_lookupzLocalsDictNodeNG._scope_lookupK   s    	!$D(94HE ; 4!2!2!4 fl&;&;<**466]]<v}}':':'<F   d##  	E	s   B/ /B=<B=c                Z    | j                   j                  |g       j                  |       y)zDefine that the given name is declared in the given statement node.

        .. seealso:: :meth:`scope`

        :param name: The name that is being defined.

        :param stmt: The statement that defines the given name.
        N)r   
setdefaultappend)r   r   stmts      r   	set_localzLocalsDictNodeNG.set_locala   s#     	tR(//5r   c                H    | j                   j                  |       | |_        y)z&append a child, linking it in the treeN)bodyr.   r   )r   childs     r   _append_nodezLocalsDictNodeNG._append_nodeo   s     			r   c                     y Nr   r   
child_noder   s      r   add_local_nodezLocalsDictNodeNG.add_local_nodex   s     	r   c                     y r6   r   r7   s      r   r9   zLocalsDictNodeNG.add_local_node~   s    r   Nc                p    |dk7  r| j                  |       | j                  |xs |j                  |       y)zAppend a child that should alter the locals of this scope node.

        :param child_node: The child node that will alter locals.

        :param name: The name of the local that will be altered by
            the given child node.
        	__class__N)r4   r0   r   r7   s      r   r9   zLocalsDictNodeNG.add_local_node   s1     ;j)t.z
;r   c                &    | j                   |   d   S )zThe first node the defines the given local.

        :param item: The name of the locally defined object.

        :raises KeyError: If the name is not defined.
        r   r   )r   items     r   __getitem__zLocalsDictNodeNG.__getitem__   s     {{4 ##r   c                4    t        | j                               S )zIterate over the names of locals defined in this scoped node.

        :returns: The names of the defined locals.
        :rtype: iterable(str)
        )iterkeysr   s    r   __iter__zLocalsDictNodeNG.__iter__   s     DIIK  r   c                H    t        | j                  j                               S )zThe names of locals defined in this scoped node.

        :returns: The names of the defined locals.
        :rtype: list(str)
        )listr   rC   r   s    r   rC   zLocalsDictNodeNG.keys   s     DKK$$&''r   c                N    | j                         D cg c]  }| |   	 c}S c c}w )zThe nodes that define the locals in this scoped node.

        :returns: The nodes that define locals.
        :rtype: list(NodeNG)
        )rC   )r   keys     r   valueszLocalsDictNodeNG.values   s"     &*YY[1cS	111s   "c                d    t        t        | j                         | j                                     S )zGet the names of the locals and the node that defines the local.

        :returns: The names of locals and their associated node.
        :rtype: list(tuple(str, NodeNG))
        )rF   ziprC   rI   r   s    r   itemszLocalsDictNodeNG.items   s"     C		T[[]344r   c                    || j                   v S )zCheck if a local is defined in this scope.

        :param name: The name of the local to check for.
        :type name: str

        :returns: Whether this node has a local of the given name,
        r>   )r   r   s     r   __contains__zLocalsDictNodeNG.__contains__   s     t{{""r   )returnstr)r   r   rO   r   )r   )r"   z_base_nodes.LookupMixInr   rP   r#   intrO   z+tuple[LocalsDictNodeNG, list[nodes.NodeNG]])r   rP   r/   nodes.NodeNGrO   None)r3   rR   rO   rS   ).)r8   znodes.ClassDefr   
str | NonerO   rS   )r8   rR   r   rP   rO   rS   r6   )r8   rR   r   rT   rO   rS   )r?   rP   rO   r   )rO   bool)__name__
__module____qualname____doc____annotations__r   r   r$   r+   r0   __setitem__r4   r   r9   r@   rD   rC   rI   rL   rN   r   r   r   r   r      s     -,O  GH"+"36"@C"	4"& GH$+$36$@C$	4$,
6 K =@(0:	 
  <$!(	25#r   r   c                  4    e Zd ZU dZej
                  Zded<   y)ComprehensionScopez.Scoping for different types of comprehensions.zlist[nodes.Comprehension]
generatorsN)rV   rW   rX   rY   r   r+   r$   rZ   r   r   r   r]   r]      s    8#11L))1r   r]   N)rY   
__future__r   typingr   r   r   astroid.exceptionsr   astroid.filter_statementsr   astroid.nodesr	   r
    astroid.nodes.scoped_nodes.utilsr   astroid.typingr   r   astroidr   r   LookupMixInr   r]   r   r   r   <module>rh      sS   
 ; " 3 3 1 3 3 ; ET]l#{.. l#^2) 2r   