
    ^h                        S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJr  SS	KJr  SS
KJr  SSKJrJr  SSKJr  SSKJr  SrS r\R6                  \S 5       5       r\" SS9\S 5       5       rS rS rS r g)a  
One of the really important features of |jedi| is to have an option to
understand code like this::

    def foo(bar):
        bar. # completion here
    foo(1)

There's no doubt wheter bar is an ``int`` or not, but if there's also a call
like ``foo('str')``, what would happen? Well, we'll just show both. Because
that's what a human would expect.

It works as follows:

- |Jedi| sees a param
- search for function calls named ``foo``
- execute these calls and check the input.
    )settings)debug)get_parent_scope)inference_state_method_cache)TreeArguments)get_executed_param_names)is_stdlib_path)to_list)instance)ValueSet	NO_VALUES)#get_module_contexts_containing_name)	recursion   c                    ^  U 4S jnU$ )Nc                 X  > U R                   n[        R                  " X R                  5       nU(       a<  U=R                  S-  sl         T" X5      U=R                  S-  sl        sS S S 5        $ [
        sS S S 5        $ ! U=R                  S-  sl        f = f! , (       d  f       g = f)N   )inference_stater   execution_allowed	tree_nodedynamic_params_depthr   )function_valueparam_indexinfallowedfuncs       W/home/james-whalen/.local/lib/python3.13/site-packages/jedi/inference/dynamic_params.pywrapper"_avoid_recursions.<locals>.wrapper&   s    ,,((.F.FG7 ((A-(2<,,1, HG  HG ,,1, HGs)   BBB2BBB
B) )r   r   s   ` r   _avoid_recursionsr!   %   s     N    c                   ^ ^ T R                   R                  (       d  [        $ T R                  nT R	                  5       R                  5       nUb  [        U5      (       a  [        $ UR                  S:X  a  [        U5      nUc  [        $ OUR                  R                  n[        R                  " SUSS9  T R	                  5       n[        XRU5      n[        R                  " U U4S jU 5       5      n[        R                  " SSS9  U$ )a  
A dynamic search for param values. If you try to complete a type:

>>> def func(foo):
...     foo
>>> func(1)
>>> func("")

It is not known what the type ``foo`` without analysing the whole code. You
have to look for all calls to ``func`` to find out what ``foo`` possibly
is.
lambdefzDynamic param search in %s.MAGENTA)colorc              3   ^   >#    U  H"  n[        TU5      T   R                  5       v   M$     g 7f)N)r   infer).0	argumentsr   r   s     r   	<genexpr>'dynamic_param_lookup.<locals>.<genexpr>\   s:        (I 	!I	

	uw	 (s   *-zDynamic param result finished)r   do_dynamic_params_searchr   r   get_root_context
py__file__r	   type_get_lambda_namenamevaluer   dbg_search_function_argumentsr   	from_sets)r   r   funcdefpathstring_namemodule_contextarguments_listvaluess   ``      r   dynamic_param_lookupr=   6   s     ))BB&&G**,779DN400
 ||y &w/  ll((	II+[	J#446N/UN   (	  F 
II-Y?Mr"   N)defaultc           	   #     #    UnUS:X  a3  [        U5      nUR                  S:X  a  UR                  R                  nUnSnSnU R                  n[
        R                  (       a  [        Xp/USS9nOU /nU Hi  n	[        X5       HN  u  pUS-  nXgR                  -  [        :  a      gU	R                  U
5      n[        X|X:U5       H	  nS	nUv   M     MP     U(       d  Mi    g   g7f)
z 
Returns a list of param names.
__init__classdefFr      )limit_reductionr   NT)r   r0   r2   r3   r   r    dynamic_params_for_other_modulesr   _get_potential_nodesr   MAX_PARAM_SEARCHEScreate_context_check_name_for_execution)r:   r7   r9   compare_nodeclsfound_argumentsir   module_contextsfor_mod_contextr2   trailerrandom_contextr*   s                 r   r5   r5   f   s      Lj w'88z!((..KLO	A$44O00=-{
 ***1/OMDFA
 777:LL,;;DAN6#\R	"&R P" ?' +s   CC#C#c                     U R                   nUR                  S:X  aK  [        UR                  5       S 5      nUS:X  a+  UR                  S   nUR                  S:X  a  UR
                  $ g )N	expr_stmt=r   r2   )parentr0   nextyield_operatorschildrenr3   )nodestmtfirst_operatorfirsts       r   r1   r1      s[    ;;DyyKd224d;S MM!$EzzV#{{"r"   c              #      #     U R                   R                  5       U   nU H>  nUR                  5       nUR                  nUR
                  S:X  d  M1  US:X  d  M9  X54v   M@     g ! [         a     g f = f7f)NrO   ()r   get_used_namesKeyErrorget_next_leafrT   r0   )module_valuefunc_string_namenamesr2   bracketrO   s         r   rE   rE      st     &&5578HI $$&..<<9$C-	   s3   A6A& /A6A6
A6&
A30A62A33A6c           	   #     ^ ^^#    SSK Jn  UU U4S jnT R                  TU5       GHU  nUR                  nX(:X  a  U" U5      v   M!  [	        UR
                  U5      (       d  M>  UR                  S:X  d  MP  UR
                  R                  5       n	[        U	5      S:w  a  M{  U	S   R                  5       n
U
 Vs/ s H  oR                  PM     snU/:X  d  M  TR                  5       nUR                  U" U5      5      n[        XS   R                  5      nU H_  u  nmUR                  UR                  s=:  a  UR                  :  d  M3  O  M7  UR                  U5      n[!        T UUUT5       S h  vN   Ma     GMX     g s  snf  N7f)Nr   )BaseFunctionExecutionContextc                 8  > TR                   S   nUS:X  a  S n[        TTUT5      nSSKJn  U R                  R
                  S:X  a+  [        R                  " TU R                  U U5      nU" XB5      $ U R                  5       (       a  U" U R                  U5      nU$ )Nr   )r   )InstanceArgumentsrA   )
rW   r   jedi.inference.value.instanceri   r   r0   r   TreeInstanceparent_contextis_bound_method)r3   arglistargsri   created_instancecontextr   rO   s        r   create_args._check_name_for_execution.<locals>.create_args   s    ""1%c>G_gwHC??:-'44$$	  %%5<<$$&&(>Kr"   r7   r   )jedi.inference.value.functionrf   r(   r   
isinstancerl   r0   get_param_nameslenr.   
as_contextrE   r9   	start_posend_posrG   rH   )r   rq   rI   r2   rO   rf   rr   r3   
value_nodeparam_namesr<   vr:   execution_contextpotential_nodesrP   s   ``  `           r   rH   rH      sX    J& !&&w5__
%e$$,,.JKK %%2  ..>>@K;1$ ^))+F%+,VV,>!(!9!9!;$)$4$4[5G$H!"6~ST~GaGa"b%4MD'!++dnnQz?Q?QQQ):)I)I$)O#<+*( #$   &5% 6 -s8   AF$F6AF8FFA0F'F2F3F)!__doc__jedir   r   jedi.parser_utilsr   jedi.inference.cacher   jedi.inference.argumentsr   jedi.inference.paramr   jedi.inference.helpersr	   jedi.inference.utilsr
   jedi.inference.valuer   jedi.inference.base_valuer   r   jedi.inference.referencesr   jedi.inferencer   rF   r!   increase_indentr=   r5   r1   rE   rH   r    r"   r   <module>r      s   &   . = 2 9 1 ( ) 9 I $  " +  +\ d++ 	 ,+\	
 1r"   