
    cc2                    p    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
mZ d dlmZ  G d d          Zd	S )
    )annotations)nodes)Instance)CallContextInferenceContext)InferenceError	NoDefaultUninferablec                  b    e Zd ZdZ	 	 dddZeddd            Zd	 ZddZdddZ	dddZ
d ZdS )CallSitea  Class for understanding arguments passed into a call site.

    It needs a call context, which contains the arguments and the
    keyword arguments that were passed into a given call site.
    In order to infer what an argument represents, call :meth:`infer_argument`
    with the corresponding function node and the argument name.

    :param callcontext:
        An instance of :class:`astroid.context.CallContext`, that holds
        the arguments for the call site.
    :param argument_context_map:
        Additional contexts per node, passed in from :attr:`astroid.context.Context.extra_context`
    :param context:
        An instance of :class:`astroid.context.Context`.
    Ncallcontextr   contextInferenceContext | Nonec                J   |i }|| _         |j        }|j        }t                      | _        |                     ||          | _        |                     ||          | _        d | j        D             | _	        d | j        
                                D             | _        d S )Nr   c                $    g | ]}|t           u|S  r
   .0args     1lib/python3.11/site-packages/astroid/arguments.py
<listcomp>z%CallSite.__init__.<locals>.<listcomp>.   s2     %
 %
 %
#[2H%
%
 %
 %
    c                ,    i | ]\  }}|t           u||S r   r
   r   keyvalues      r   
<dictcomp>z%CallSite.__init__.<locals>.<dictcomp>1   s9     "
 "
 "
UK'"
"
 "
 "
r   )argument_context_mapargskeywordssetduplicated_keywords_unpack_args_unpacked_args_unpack_keywords_unpacked_kwargspositional_argumentsitemskeyword_arguments)selfr   r    r   r!   r"   s         r   __init__zCallSite.__init__   s       	&#% $8!'-0UU "//g/FF $ 5 5h 5 P P%
 %
.%
 %
 %
!"
 "
"399;;"
 "
 "
r   c                p    |pt                      }t          |j        |j                  } | ||          S )zxGet a CallSite object from the given Call node.

        context will be used to force a single inference path.
        r   )r   r   r!   r"   )cls	call_noder   r   s       r   	from_callzCallSite.from_call7   s>     /-//!).)2DEEs;0000r   c                V    t          | j                  t          | j                  k    S )ao  Check if in the current CallSite were passed *invalid* arguments.

        This can mean multiple things. For instance, if an unpacking
        of an invalid object was passed, then this method will return True.
        Other cases can be when the arguments can't be inferred by astroid,
        for example, by passing objects which aren't known statically.
        )lenr)   r&   r,   s    r   has_invalid_argumentszCallSite.has_invalid_argumentsC   s%     4,--T5H1I1IIIr   returnboolc                V    t          | j                  t          | j                  k    S )ag  Check if in the current CallSite were passed *invalid* keyword arguments.

        For instance, unpacking a dictionary with integer keys is invalid
        (**{1:2}), because the keys must be strings, which will make this
        method to return True. Other cases where this might return True if
        objects which can't be inferred were passed.
        )r3   r+   r(   r4   s    r   has_invalid_keywordszCallSite.has_invalid_keywordsM   s%     4)**c$2G.H.HHHr   c                   i }|pt                      }| j        |_        |D ]b\  }}|T	 t          |                    |                    }n%# t
          $ r t          ||<   Y Dt          $ r Y Ow xY wt          |t          j
                  st          ||<   x|j        D ]\  }}	 t          |                    |                    }n%# t
          $ r t          ||<   Y @t          $ r Y Kw xY wt          |t          j                  st          ||<   tt          |j        t                    st          ||<   |j        |v r/t          ||j        <   | j                            |j                   |||j        <   ܐ]|||<   d|S )Nr   )r   r    extra_contextnextinferr   r   StopIteration
isinstancer   Dictr*   Constr   strr$   add)	r,   r"   r   valuesnamer   inferreddict_key
dict_values	            r   r'   zCallSite._unpack_keywordsW   s   /-// $ 9# %	% %	%KD% $%#EKKK$@$@AAHH%   #.F4LH$   H "(EJ77 #.F4L,4N 8 8(Hj!#'w(G(G#H#H) ! ! !'2t ( ! ! ! !%h<< !'2t %hnc:: !'2t ~/ !1<x~.044X^DDD -7F8>**'8*  %ts/   #AA1%	A10A1&#C

C, 	C,+C,c                <   g }|pt                      }| j        |_        |D ]}t          |t          j                  r	 t          |j                            |                    }n5# t          $ r |
                    t                     Y lt          $ r Y ww xY w|t          u r|
                    t                     t          |d          s|
                    t                     |                    |j                   |
                    |           |S )Nr   elts)r   r    r;   r?   r   Starredr<   r   r=   r   appendr   r>   hasattrextendrJ   )r,   r!   r   rD   r   rF   s         r   r%   zCallSite._unpack_args   s/   /-// $ 9 	# 	#C#u}-- ##CIOOGO$D$DEEHH%   MM+...H$   H {* MM+...x00 MM+...hm,,,,c""""s   (A''$B	BBc           	     	   || j         v rt          d| |||          	 | j        |                             |          S # t          $ r Y nw xY wt          | j                  t          |j        j                  k    r,|j        j        s |j        j	        st          d| |||          | j        dt          |j        j                           }| j        t          |j        j                  d         }|j        
                    |          d         }d |j        j        D             fd| j                                        D             }t          |          t          |j        j                  k     rG|j        j        D ]:}|j        |v r/|                    |j                  }	|                    |	           ;|ct!          |dd          }
|dk    r
|j        d	v r |
)|j        d
k    r|r|d                             |          S |
|j                            d          }
t)          |
t*          j                  r?|j                                        }||
                                u rt3          |
f          S |j        d
k    r9t)          |
t4                    s|
                                }
t3          |
f          S |j        dk    rt3          |
f          S |j        d	v r|
r|dz  }	 | j        |                             |          S # t8          $ r Y nw xY w|j        j        |k    r|                                 r t          d| j        | j        | |||          t+          j         |j        j!        |j        j"        |j                  }|#                    d |                                D                        t3          |f          S |j        j        |k    r| $                                r t          d| j        | j%        | |||          t+          j&        |j        j!        |j        j"        |j                  }|#                    |           t3          |f          S 	 |j        '                    |                              |          S # tP          $ r Y nw xY wt          d| |||          )a  Infer a function argument value according to the call context.

        Arguments:
            funcnode: The function being called.
            name: The name of the argument whose value is being inferred.
            context: Inference context object
        z9The arguments passed to {func!r} have duplicate keywords.)	call_sitefuncr   r   zJToo many positional arguments passed to {func!r} that does not have *args.Nr   c                    h | ]	}|j         
S r   )rE   r   s     r   	<setcomp>z*CallSite.infer_argument.<locals>.<setcomp>   s    CCC3chCCCr   c                $    i | ]\  }}|v	||S r   r   )r   r   r   
kwonlyargss      r   r   z+CallSite.infer_argument.<locals>.<dictcomp>   s:     
 
 
U*$

 
 
r   	boundnode>   methodclassmethodrW   r   T)futurerX      zInference failed to find values for all keyword arguments to {func!r}: {unpacked_kwargs!r} doesn't correspond to {keyword_arguments!r}.)r+   unpacked_kwargsrP   rQ   r   r   )lineno
col_offsetparentc                @    g | ]\  }}t          j        |          |fS r   )r   const_factoryr   s      r   r   z+CallSite.infer_argument.<locals>.<listcomp>  s,    TTTzsE%%c**E2TTTr   zInference failed to find values for all positional arguments to {func!r}: {unpacked_args!r} doesn't correspond to {positional_arguments!r}.)r)   unpacked_argsrP   rQ   r   r   z-No value found for argument {arg} to {func!r}))r$   r   r+   r=   KeyErrorr3   r)   r!   varargposonlyargsfind_argnamerU   r*   rE   poprL   getattrtyper^   framer?   r   ClassDefscope	metaclassiterr   instantiate_class
IndexErrorkwargr9   r(   r@   r\   r]   postinitr5   r&   Tupledefault_valuer	   )r,   funcnoderE   r   
positionalrc   argindexkwargsfunc_argr   rV   method_scoperp   r!   rU   s                 @r   infer_argumentzCallSite.infer_argument   s    4++ 	 K   	)$/55g>>> 	 	 	D	 t())C0B,C,CC 
	=' 	0I 	$& #!#    ./HX]5G1H1H/HI
*3x}/A+B+B+D+DE=--d33A6CC(-*BCCC

 
 
 
"4::<<
 
 
 z??S!3444 	+$M. + +=F* + **X]33C%%c*** %	d;;I1} .2K!K .  @()B @z @%a=..w.??? C ( 5 5T 5 B BIi88 2
 $,?#8#8#:#:L#y':':'<'<< 2#YL111=H, .%i:: B$-$?$?$A$A	---=M1 .--- } 99 i A0:@@III    =$& 	" ((** $- '+&<$($9"!#
 
 
 
 J}+#=3}  E
 NNTTV\\^^TTT   >>!=4' 	! ))++ $> *.)B"&"5"!#
 
 
 
 ;}+#=3}  D
 MM&!!!== 	=..t44::7CCC 	 	 	D	;
 
 
 	
s5   A   
AA9L 
L&%L&8,R% %
R21R2)NN)r   r   r   r   )N)r   r   )r6   r7   )__name__
__module____qualname____doc__r-   rX   r1   r5   r9   r'   r%   rz   r   r   r   r   r      s         & "+/	
 
 
 
 
0 	1 	1 	1 	1 [	1J J JI I I I* * * * *X    2Y
 Y
 Y
 Y
 Y
r   r   N)
__future__r   astroidr   astroid.basesr   astroid.contextr   r   astroid.exceptionsr   r	   astroid.utilr   r   r   r   r   <module>r      s   
 # " " " " "       " " " " " " 9 9 9 9 9 9 9 9 8 8 8 8 8 8 8 8 $ $ $ $ $ $g
 g
 g
 g
 g
 g
 g
 g
 g
 g
r   