
    f                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
m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 dZd Zej6                  ed               Z ed      ed               Zd Zd Zd Z y)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                       fd}|S )Nc                 F   | j                   }t        j                  || j                        5 }|r=|xj                  dz  c_        	  | |      |xj                  dz  c_        cd d d        S t
        cd d d        S # |xj                  dz  c_        w xY w# 1 sw Y   y xY w)N   )inference_stater   execution_allowed	tree_nodedynamic_params_depthr   )function_valueparam_indexinfallowedfuncs       X/var/www/cvtools/html/venv/lib/python3.12/site-packages/jedi/inference/dynamic_params.pywrapperz"_avoid_recursions.<locals>.wrapper&   s    ,,((n.F.FG 
	7 ((A-(2<,,1,
	 
	 
	 
	 ,,1,
	 
	s)   BA=B.B=BBB  )r   r   s   ` r   _avoid_recursionsr    %   s     N    c                      j                   j                  st        S  j                  } j	                         j                         }|t        |      rt        S |j                  dk(  rt        |      }|t        S |j                  j                  }t        j                  d|d        j	                         }t        |||      }t        j                   fd|D              }t        j                  dd       |S )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   X   K   | ]!  }t        |         j                          # y w)N)r   infer).0	argumentsr   r   s     r   	<genexpr>z'dynamic_param_lookup.<locals>.<genexpr>\   s9         	!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
 ||y &w/ll((	II+[	J#446N/UN   (	  F 
II-Y?Mr!   N)defaultc           	   #     K   |}|dk(  r2t        |      }|j                  dk(  r|j                  j                  }|}d}d}| j                  }t
        j                  rt        || g|d      }n| g}|D ]c  }	t        |	|      D ]N  \  }
}|dz  }||j                  z  t        kD  r  y|	j                  |
      }t        ||||
|      D ]  }d	}| 
 P |sc y yw)
z(
    Returns a list of param names.
    __init__classdefFr      )limit_reductionr   NT)r   r.   r0   r1   r   r    dynamic_params_for_other_modulesr   _get_potential_nodesr   MAX_PARAM_SEARCHEScreate_context_check_name_for_execution)r8   r5   r7   compare_nodeclsfound_argumentsir   module_contextsfor_mod_contextr0   trailerrandom_contextr)   s                 r   r3   r3   f   s	     Lj w'88z!((..KLO	A$44O00=n-{
 *** 1/;O 	 MD'FA
 ?777:LL,;;DAN6#^\4R  	"& 	 " 's   CCCc                     | j                   }|j                  dk(  rIt        |j                         d       }|dk(  r*|j                  d   }|j                  dk(  r|j
                  S y )N	expr_stmt=r   r0   )parentr.   nextyield_operatorschildrenr1   )nodestmtfirst_operatorfirsts       r   r/   r/      s[    ;;DyyKd224d;S MM!$EzzV#{{"r!   c              #      K   	 | j                   j                         |   }|D ]:  }|j                         }|j                  }|j
                  dk(  s/|dk(  s5||f < y # t        $ r Y y w xY ww)NrM   ()r   get_used_namesKeyErrorget_next_leafrR   r.   )module_valuefunc_string_namenamesr0   bracketrM   s         r   rC   rC      s|     &&5578HI   $$&..<<9$C-	   s3   A0A! 0A0A0	A0!	A-*A0,A--A0c           	   #      K   ddl m}  fd} j                  |      D ]@  }|j                  }||k(  r ||        t	        |j
                  |      s7|j                  dk(  sG|j
                  j                         }	t        |	      dk7  rp|	d   j                         }
|
D cg c]  }|j                   c}|gk(  sj                         }|j                   ||            }t        ||	d   j                        }|D ]Z  \  }|j                  |j                  cxk  r|j                  k  s0n 3|j                  |      }t!         |||      E d {    \ C y c c}w 7 w)Nr   )BaseFunctionExecutionContextc                 *   j                   d   }|dk(  rd }t        |      }ddlm} | j                  j
                  dk(  r+t        j                  | j                  | |      } |||      S | j                         r || j                  |      }|S )Nr   )r   )InstanceArgumentsr?   )
rU   r   jedi.inference.value.instancerg   r   r.   r   TreeInstanceparent_contextis_bound_method)r1   arglistargsrg   created_instancecontextr   rM   s        r   create_argsz._check_name_for_execution.<locals>.create_args   s    ""1%c>G_gwHC??:-'44$$	  %%5t<<$$&(>Kr!   r5   r   )jedi.inference.value.functionrd   r'   r   
isinstancerj   r.   get_param_nameslenr,   
as_contextrC   r7   	start_posend_posrE   rF   )r   ro   rG   r0   rM   rd   rp   r1   
value_nodeparam_namesr:   vr8   execution_contextpotential_nodesrN   s   ``  `           r   rF   rF      s_    J& !&&w5 __
:%e$$,,.JK %%2  ..>>@K;1$ ^))+F%+,,>!(!9!9!;$)$4$4[5G$H!"6~{ST~GaGa"b%4 	MD'!++dnnQz?Q?QQ):)I)I$)O#<+*( #$  	% -s8   AE1E1,A E1,E*?E1A1E19&E1E/ E1)!__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   rD   r    increase_indentr;   r3   r/   rC   rF   r   r!   r   <module>r      s   &   . = 2 9 1 ( ) 9 I $  " +  +\ d++ 	 ,+\	
 1r!   