
    7g2                    |    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 d dlmZmZmZ  G d d	      Zy
)    )annotations)nodes)Instance)CallContextInferenceContext)InferenceError	NoDefault)InferenceResult)UninferableUninferableBase
safe_inferc                  v    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d	Zy)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`.
    Nc                   |i }|| _         |j                  }|j                  }t               | _        | j                  ||      | _        | j                  ||      | _        | j                  D cg c]  }t        |t              r| c}| _        | j                  j                         D ci c]  \  }}t        |t              s|| c}}| _        y c c}w c c}}w Ncontext)argument_context_mapargskeywordssetduplicated_keywords_unpack_args_unpacked_args_unpack_keywords_unpacked_kwargs
isinstancer   positional_argumentsitemskeyword_arguments)	selfcallcontextr   r   r   r   argkeyvalues	            1lib/python3.12/site-packages/astroid/arguments.py__init__zCallSite.__init__    s      '#% $8!''-0U "//g/F $ 5 5h 5 P  ..%
.Cjo6VC.%
!
 #3399;"
;
Ue_5 J;"
%
"
s   1CC0Cc                r    |xs
 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_call8   s5     /-/!)..)2D2DE;00    c                X    t        | j                        t        | j                        k7  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_argumentsD   s%     4,,-T5H5H1IIIr,   c                X    t        | j                        t        | j                        k7  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.
        )r.   r    r   r/   s    r&   has_invalid_keywordszCallSite.has_invalid_keywordsN   s%     4))*c$2G2G.HHHr,   c                L   i }|xs
 t               }| j                  |_        |D ]  \  }}|t        ||      }t	        |t
        j                        s
t        ||<   9|j                  D ]  \  }}t        ||      }t	        |t
        j                        s
t        ||<   7t	        |j                  t              s
t        ||<   [|j                  |v r9t        ||j                  <   | j                  j                  |j                         |||j                  <    |||<    |S r   )r   r   extra_contextr   r   r   Dictr   r   Constr%   strr   add)	r!   r   r   valuesnamer%   inferreddict_key
dict_values	            r&   r   zCallSite._unpack_keywordsX   s   
 57/-/ $ 9 9#KD%|%eW=!(EJJ7#.F4L,4NN(Hj)(GDH%h<'2t %hnnc:'2t ~~/1<x~~.0044X^^D -7F8>>* -;  %t1 $2 r,   c                   g }|xs
 t               }| j                  |_        |D ]  }t        |t        j
                        r{t        |j                  |      }t        |t              r|j                  t               Zt        |d      s|j                  t               ||j                  |j                         |j                  |        |S )Nr   elts)r   r   r4   r   r   Starredr   r%   r   appendr   hasattrextendr?   )r!   r   r   r9   r#   r;   s         r&   r   zCallSite._unpack_args{   s    /-/ $ 9 9C#u}}-%ciiAh8MM+.x0MM+.hmm,c"  r,   c           	         t        |t        j                  t        j                  f      st	        d|d| |||      || j
                  v rt	        d| |||      	 | j                  |   j                  |      S # t        $ r Y nw xY wt        | j                        t        |j                  j                        kD  r<|j                  j                  s&|j                  j                  st	        d| |||      | j                  dt        |j                  j                         }| j                  t        |j                  j                        d }||j                  j                  |j                  j                  fv rd}n|j                  j                  |      d   }|j                  j                   D ch c]  }|j"                   nc c}w }}| j                  j%                         D 	
ci c]  \  }	}
|	|vr|	|
 nc c}
}	w }}	}
t        |      t        |j                  j                        k  rV|j                  j                  D ]=  }|j"                  |v s|j'                  |j"                        }|j)                  |       ? |P|j*                  }|dk(  r|j,                  dv r|&|j,                  d	k(  r|r|d   j                  |
      S ||j.                  j1                         }t        |t        j2                        r:|j.                  j5                         }||j7                  |
      u rt9        |f      S |j,                  d	k(  r,t        |t:              s|j=                         }t9        |f      S |j,                  dk(  rt9        |f      S |j,                  dv r|r|dz  }	 | j                  |   j                  |      S # t>        $ r Y nw xY w|j                  j                  |k(  r| jA                         r&t	        d| j                  | jB                  | |||      t        jD                  |j                  jF                  |j                  jH                  |j                  |j                  jJ                  |j                  jL                        }|jO                  |j%                         D 	
cg c]  \  }	}
t        jP                  |	      |
f nc c}
}	w c}
}	       t9        |f      S |j                  j                  |k(  r| jS                         r&t	        d| j                  | jT                  | |||      t        jV                  |j                  jF                  |j                  jH                  |j                        }|jO                  |       t9        |f      S 	 |j                  jY                  |      j                  |      S # tZ        $ r Y nw xY wt	        d| |||      )z>Infer a function argument value according to the call context.z<Can not infer function argument value for non-function node .)	call_sitefuncr#   r   z9The arguments passed to {func!r} have duplicate keywords.zJToo many positional arguments passed to {func!r} that does not have *args.Nr   >   methodclassmethodrH   r   rI      zInference failed to find values for all keyword arguments to {func!r}: {unpacked_kwargs!r} doesn't correspond to {keyword_arguments!r}.)r    unpacked_kwargsrF   rG   r#   r   )lineno
col_offsetparent
end_linenoend_col_offsetzInference failed to find values for all positional arguments to {func!r}: {unpacked_args!r} doesn't correspond to {positional_arguments!r}.)r   unpacked_argsrF   rG   r#   r   )rL   rM   rN   z-No value found for argument {arg} to {func!r}).r   r   FunctionDefLambdar   r   r    inferKeyErrorr.   r   r   varargposonlyargskwargfind_argname
kwonlyargsr:   r   poprA   	boundnodetyperN   frameClassDefscope	metaclassiterr   instantiate_class
IndexErrorr2   r   r5   rL   rM   rO   rP   postinitconst_factoryr0   r   Tupledefault_valuer	   )r!   funcnoder:   r   
positionalrV   argindexr#   rZ   r$   r%   kwargsfunc_argr\   method_scoperX   r   s                    r&   infer_argumentzCallSite.infer_argument   sk    (U%6%6$EF NxlZ[\  4+++ K 	))$/55g>> 		 t(()C0B0B,CC==''0I0I$& #!#  ../HX]]5G5G1HI
**3x}}/A/A+B+DE HMM(((--*=*=>>H}}11$7:H*2--*B*BC*B3chh*BC
C #44::<
<
U*$ J<
 
 z?S!3!344$MM..==F* **X]]3C%%c* /
 ))I1}2K!K $()Bz%a=..w.??$ ( 5 5 7Ii8
 $,??#8#8#:L#y':':7':'KK#YL11==H,%i:$-$?$?$A	--==M1-- }} 99iA00:@@II  ==$& ((*$- '+&<&<$($9$9"!#
 
 JJ}}++#==33}}#==33'}};;E NNEK\\^T^zsE%%%c*E2^T >!==4' ))+$> *.)B)B"&"5"5"!#
 
 ;;}}++#==33}}D
 MM&!= 	==..t4::7CC 		;
 	
sH   A< <	BB;G3H5O 	OO!S&
7)W! !	W-,W-)NN)r"   r   r   InferenceContext | None)N)r   rp   )returnbool)r   z%list[tuple[str | None, nodes.NodeNG]]r   rp   )ri   r
   r:   r7   r   r   )__name__
__module____qualname____doc__r'   rI   r+   r0   r2   r   r   ro    r,   r&   r   r      s    & "+/	
 
 )	
0 	1 	1JI ,0!7! )!F$f
'f
/2f
=Mf
r,   r   N)
__future__r   astroidr   astroid.basesr   astroid.contextr   r   astroid.exceptionsr   r	   astroid.typingr
   astroid.utilr   r   r   r   rw   r,   r&   <module>r      s+   
 #  " 9 8 * A Ad
 d
r,   