
    c                        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
mZ ddlmZ ddlmZ erddlmZ  ed	          Z G d
 de
j                  Z G d de          ZdS )z4This module contains mixin classes for scoped nodes.    )annotations)TYPE_CHECKINGTypeVaroverload)_filter_stmts)node_classesscoped_nodes)builtin_lookup)SuccessfulInferenceResult)nodes_Tc                      e Zd ZU dZi Zded<   	 d'dZd(d	Zd)d*dZd)dZ	d+dZ
e
Zd,dZe	 d-d.d            Zed/d            Zd0d1dZd2d Zd! Zd" Zd# Zd$ Zd3d&ZdS )4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[SuccessfulInferenceResult]]localsreturnstrc                    | j         | j        S | j                             d                                           d| j         S )zGet the 'qualified' name of the node.

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

        :returns: The qualified name.
        :rtype: str
        NT)future.)parentnameframeqnameselfs    @lib/python3.11/site-packages/astroid/nodes/scoped_nodes/mixin.pyr   zLocalsDictNodeNG.qname!   sK     ; 	9+##4#006688FF49FFF    r   r   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.scope.   s	     r   r   r   offsetintc                    t           )aB  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.
        :type node: NodeNG

        :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).
        :rtype: tuple(str, list(NodeNG))
        )NotImplementedError)r   noder   r!   s       r   scope_lookupzLocalsDictNodeNG.scope_lookup6   s
      "!r   c                v   	 t          || j        |         | |          }n# t          $ r d}Y nw xY w|r| |fS | j        o| j                                        }|Rt          |t          j                  s|                    ||          S |j        o|j                                        }|Rt          |          S )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_lookupH   s    	!$D(94HHEE 	 	 	EEE	 	; 4!2!2!4!4 	=fl&;<< 7**4666]<v}':':'<'<F  	= d###s     //stmtnodes.NodeNGNonec                b    | j                             |g                               |           dS )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   r.   s      r   	set_localzLocalsDictNodeNG.set_local\   s0     	tR((//55555r   childc                H    | j                             |           | |_        dS )z&append a child, linking it in the treeN)bodyr3   r   )r   r5   s     r   _append_nodezLocalsDictNodeNG._append_nodej   s%     		r   .
child_nodenodes.ClassDef
str | Nonec                    d S Nr   r   r9   r   s      r   add_local_nodezLocalsDictNodeNG.add_local_nodes   s	     	r   c                    d S r=   r   r>   s      r   r?   zLocalsDictNodeNG.add_local_nodey   s    r   Nc                v    |dk    r|                      |           |                     |p|j        |           dS )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)r8   r4   r   r>   s      r   r?   zLocalsDictNodeNG.add_local_node}   sF     ; 	*j)))t.z
;;;;;r   itemr   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   rC   s     r   __getitem__zLocalsDictNodeNG.__getitem__   s     {4 ##r   c                D    t          |                                           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     DIIKK   r   c                N    t          | j                                                  S )zThe names of locals defined in this scoped node.

        :returns: The names of the defined locals.
        :rtype: list(str)
        )listr   rI   r   s    r   rI   zLocalsDictNodeNG.keys   s      DK$$&&'''r   c                D      fd                                  D             S )zThe nodes that define the locals in this scoped node.

        :returns: The nodes that define locals.
        :rtype: list(NodeNG)
        c                     g | ]
}|         S r   r   ).0keyr   s     r   
<listcomp>z+LocalsDictNodeNG.values.<locals>.<listcomp>   s    111cS	111r   )rI   r   s   `r   valueszLocalsDictNodeNG.values   s'     2111TYY[[1111r   c                    t          t          |                                 |                                                     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))
        )rL   ziprI   rR   r   s    r   itemszLocalsDictNodeNG.items   s,     C		T[[]]33444r   boolc                    || 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,
        rE   )r   r   s     r   __contains__zLocalsDictNodeNG.__contains__   s     t{""r   )r   r   )r   r   r   r   )r   )r   r   r!   r"   )r   r   r.   r/   r   r0   )r5   r/   r   r0   ).)r9   r:   r   r;   r   r0   )r9   r/   r   r   r   r0   r=   )r9   r/   r   r;   r   r0   )rC   r   r   r   )r   rV   )__name__
__module____qualname____doc__r   __annotations__r   r    r&   r-   r4   __setitem__r8   r   r?   rF   rJ   rI   rR   rU   rX   r   r   r   r   r      s          :<F;;;;OG G G G   " " " " "$$ $ $ $(
6 
6 
6 
6 K    =@    X
    X< < < < <$ $ $ $! ! !( ( (	2 	2 	25 5 5# # # # # #r   r   c                  ,    e Zd ZU dZej        Zded<   dS )ComprehensionScopez.Scoping for different types of comprehensions.zlist[nodes.Comprehension]
generatorsN)rY   rZ   r[   r\   r   r-   r&   r]   r   r   r   r`   r`      s,         88#1L))))11r   r`   N)r\   
__future__r   typingr   r   r   astroid.filter_statementsr   astroid.nodesr   r	    astroid.nodes.scoped_nodes.utilsr
   astroid.typingr   astroidr   r   LookupMixInr   r`   r   r   r   <module>rj      s  
 ; : " " " " " " 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 ; ; ; ; ; ; 4 4 4 4 4 4 WT]]h# h# h# h# h#|/ h# h# h#V2 2 2 2 2) 2 2 2 2 2r   