
    7g                       U d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	m
Z
 ddlmZmZ e	rddlmZmZ ddlmZmZ eed	e
e   e
e   e
e   f   ed	   f   Zi Zd
ed<   ddZ G d d      Z G d d      ZddZ	 	 	 	 	 	 ddZy)zIVarious context related utilities, including inference and call contexts.    )annotationsN)IteratorSequence)TYPE_CHECKINGOptional)InferenceResultSuccessfulInferenceResult)
constraintnodes)KeywordNodeNGr   _InferenceCache_INFERENCE_CACHEc                 ,    t         j                          y N)r   clear     /lib/python3.12/site-packages/astroid/context.py_invalidate_cacher      s    r   c                      e Zd ZdZdZdZ	 	 d	 	 	 	 	 ddZedd       Zej                  dd       Zedd       Z
dd	Zdd
Zej                  dd       ZddZddZy)InferenceContextzProvide context for inference.

    Store already inferred nodes to save time
    Account for already visited nodes to stop infinite recursion
    )path
lookupnamecallcontext	boundnodeextra_contextconstraints_nodes_inferredd   Nc                    |	dg| _         n|| _         |xs
 t               | _        	 d | _        	 d | _        	 d | _        	 i | _        	 i | _        y Nr   )r   setr   r   r   r   r   r   )selfr   nodes_inferreds      r   __init__zInferenceContext.__init__2   so    
 !$%3D #1D MCE		 '+	 04D;?	 QSZRT'r   c                     | j                   d   S )z
        Number of nodes inferred in this context and all its clones/descendents.

        Wrap inner value in a mutable cell to allow for mutating a class
        variable in the presence of __slots__
        r   r   r$   s    r   r%   zInferenceContext.nodes_inferredU   s     ##A&&r   c                "    || j                   d<   y r"   r(   )r$   values     r   r%   zInferenceContext.nodes_inferred_   s    "'Qr   c                    t         S )z
        Inferred node contexts to their mapped results.

        Currently the key is ``(node, lookupname, callcontext, boundnode)``
        and the value is tuple of the inferred results
        )r   r)   s    r   inferredzInferenceContext.inferredc   s
      r   c                x    | j                   }||f| j                  v ry| j                  j                  ||f       y)zPush node into inference path.

        Allows one to see if the given node has already
        been looked at for this inference context
        TF)r   r   add)r$   nodenames      r   pushzInferenceContext.pushm   s7     $<499$		tTl#r   c                   t        | j                  j                         | j                        }| j                  |_        | j
                  |_        | j                  |_        | j                  j                         |_        |S )zClone inference path.

        For example, each side of a binary operation (BinOp)
        starts with the same context but diverge as each side is inferred
        so the InferenceContext will need be cloned
        )r%   )r   r   copyr   r   r   r   r   )r$   clones     r   r5   zInferenceContext.clonez   sd     !!1$BVBVW ,,.."00 ,,113r   c              #  L   K   t        | j                        }d  || _        y wr   )r#   r   )r$   r   s     r   restore_pathzInferenceContext.restore_path   s     499~	s   "$c                    | j                    xrg | j                   xrX | j                   xrI | j                   xr: | j                   xr+ | j                   xr | j
                   xr | j                   S r   )r   r%   r   r   r   r   r   r)   s    r   is_emptyzInferenceContext.is_empty   s    		M %'''%$$$% NN"% OO#	%
 $$$% &&&% $$$		
r   c                      fd j                   D        }dj                  t               j                  dj	                  |            S )Nc           
   3     K   | ]6  }| d t        j                  t        |      dt        |      z
          8 yw)=P   )widthN)pprintpformatgetattrlen).0fieldr$   s     r   	<genexpr>z+InferenceContext.__str__.<locals>.<genexpr>   s?      
' gQv~~gdE&:"s5z/RST's   <?z{}({})z,
    )	__slots__formattype__name__join)r$   states   ` r   __str__zInferenceContext.__str__   s<    

 tDz22INN54IJJr   NN)r   z+set[tuple[nodes.NodeNG, str | None]] | Noner%   zlist[int] | NonereturnNone)rN   int)r+   rP   rN   rO   )rN   r   )r0   znodes.NodeNGrN   bool)rN   r   )rN   zIterator[None])rN   rQ   )rN   str)rI   
__module____qualname____doc__rF   max_inferredr&   propertyr%   setterr-   r2   r5   
contextlibcontextmanagerr7   r9   rL   r   r   r   r   r      s    I L =A+/!(9!( )!( 
	!(F ' ' ( (      


Kr   r   c                  ,    e Zd ZdZdZ	 	 d	 	 	 	 	 ddZy)CallContextz"Holds information for a call site.)argskeywordscalleeNc                    || _         |r&|D cg c]  }|j                  |j                  f }}ng }|| _        || _        y c c}w r   )r]   argr+   r^   r_   )r$   r]   r^   r_   ra   arg_value_pairss         r   r&   zCallContext.__init__   sH     	?GHx3xOH O'	 Is   ArM   )r]   zlist[NodeNG]r^   zlist[Keyword] | Noner_   zInferenceResult | None)rI   rS   rT   rU   rF   r&   r   r   r   r\   r\      s3    ,.I
 *.)-	 ' '	r   r\   c                :    | | j                         S t               S )z4Clone a context if given, or return a fresh context.)r5   r   )contexts    r   copy_contextre      s    }}r   c                *    t        |       } || _        | S )zGive a context a boundnode
    to retrieve the correct function name or attribute value
    with from further inference.

    Do not use an existing context since the boundnode could then
    be incorrectly propagated higher up in the call stack.
    )re   r   )rd   r0   s     r   bind_context_to_noderg      s     7#GGNr   )rN   rO   )rd   InferenceContext | NonerN   r   )rd   rh   r0   r	   rN   r   )rU   
__future__r   rY   r?   collections.abcr   r   typingr   r   astroid.typingr   r	   astroidr
   r   astroid.nodes.node_classesr   r   dicttuplerR   r   r   __annotations__r   r   r\   re   rg   r   r   r   <module>rr      s   
 P "   . * E):	(HSM8C=(3-
?@(8BTT %' / &AK AKH ($,Er   