
    e                        U d Z ddl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 ddlmZ dd	lmZmZmZ  e       Zd
ed<    e       Zded<    e	de      ZddZddZ	 d	 	 	 	 	 ddZy)z,Transform utilities (filters and decorator).    )annotations)OrderedDict)	Generator)AnyTypeVar)InferenceContext)InferenceOverwriteErrorUseInferenceDefault)NodeNG)InferenceResultInferFnTransformFnzXOrderedDict[tuple[InferFn[Any], NodeNG, InferenceContext | None], list[InferenceResult]]_cachez set[tuple[InferFn[Any], NodeNG]]_CURRENTLY_INFERRING_NodesT)boundc                 ,    t         j                          y)zClear the inference tips cache.N)r   clear     7/usr/lib/python3/dist-packages/astroid/inference_tip.pyclear_inference_tip_cacher      s    
LLNr   c                &     	 d	 	 	 	 	 	 	 d fd}|S )z(Cache decorator used for inference tips.c              ;    K   | f}|t         v rt         j                  |       t        ||j                         rd }	 t        | |f   E d {    y 7 # t
        $ r t         j                  |       	 t         | |fi |      x}t        | |f<   n# t        $ r}|d d }~ww xY w	 	 t         j                  |       n# t
        $ r Y nw xY wt        t              dkD  rkt        j                  d       nT# 	 t         j                  |       n# t
        $ r Y nw xY wt        t              dkD  rt        j                  d       w w xY wY nw xY w|E d {  7   y w)N@   F)last)r   remover
   is_emptyr   KeyErroraddlist	Exceptionlenpopitem)nodecontextkwargspartial_cache_keyresultefuncs         r   innerz$_inference_tip_cached.<locals>.inner'   sq    
 "4L 44 !''(9:%%7#3#3#5G	/dD'1222 3 	/ !$$%67/7;w1&18 dG 34  "T!" 5(//0AB  v;#NNN.(//0AB  v;#NNN. $-	/4 s   <E  A AA E A E6BC:	B'B""B''C:,CE	CEC,E:E<DE	D	ED	-EEE EE EE )N)r%   r   r&   zInferenceContext | Noner'   r   returnz&Generator[InferenceResult, None, None]r   )r+   r,   s   ` r   _inference_tip_cachedr.   $   s9    
 ,0++(+ + 
0	+Z Lr   c                "    | f	 	 	 	 	 dfd}|S )a  Given an instance specific inference function, return a function to be
    given to AstroidManager().register_transform to set this inference function.

    :param bool raise_on_overwrite: Raise an `InferenceOverwriteError`
        if the inference tip will overwrite another. Used for debugging

    Typical usage

    .. sourcecode:: python

       AstroidManager().register_transform(Call, inference_tip(infer_named_tuple),
                                  predicate)

    .. Note::

        Using an inference tip will override
        any previously set inference tip for the given
        node. Use a predicate in the transform to prevent
        excess overwrites.
    c                    rA| j                   5| j                   |ur't        dj                  || j                   |             t        |      | _         | S )NzbInference already set to {existing_inference}. Trying to overwrite with {new_inference} for {node})existing_inferencenew_inferencer%   )_explicit_inferencer	   formatr.   )r%   infer_functionraise_on_overwrites     r   	transformz inference_tip.<locals>.transformo   sj     ((4((>)FFLf'5"&":": GM G  $9#H r   )r%   r   r5   InferFn[_NodesT]r-   r   r   )r5   r6   r7   s    ` r   inference_tipr9   W   s.    2 ;I'7	& r   N)r-   None)r+   r8   r-   r8   )F)r5   r8   r6   boolr-   zTransformFn[_NodesT])__doc__
__future__r   collectionsr   collections.abcr   typingr   r   astroid.contextr   astroid.exceptionsr	   r
   astroid.nodesr   astroid.typingr   r   r   r   __annotations__setr   r   r   r.   r9   r   r   r   <module>rG      s   
 3 " # %  , K    M  	  := 6 >
)6
*
0h BG+$+:>++r   