Format: application/x-python-code
⬇ Download File (5.7 KB)
   1  o
   2  
   3  �h��@s�dZddlmZddlmZddlmZddlmZddlm	Z	ddl
   4  mZddlm
   5  Z
   6  dd	lmZdd
   7  lmZddlmZmZddlmZdd
   8  lmZdZdd�Zejedd���Zedd�edd���Zdd�Zdd�Zdd�Z dS)a�
   9  One of the really important features of |jedi| is to have an option to
  10  understand code like this::
  11  
  12      def foo(bar):
  13          bar. # completion here
  14      foo(1)
  15  
  16  There's no doubt wheter bar is an ``int`` or not, but if there's also a call
  17  like ``foo('str')``, what would happen? Well, we'll just show both. Because
  18  that's what a human would expect.
  19  
  20  It works as follows:
  21  
  22  - |Jedi| sees a param
  23  - search for function calls named ``foo``
  24  - execute these calls and check the input.
  25  �)�settings)�debug)�get_parent_scope)�inference_state_method_cache)�
  26  TreeArguments)�get_executed_param_names)�is_stdlib_path)�to_list)�instance)�ValueSet�	NO_VALUES)�#get_module_contexts_containing_name)�	recursion�cs�fdd�}|S)Nc
  27  s�|j}t�||j��0}|r1|jd7_z�||�W|jd8_Wd�S|jd8_wtWd�S1s=wYdS)N�)�inference_staterZexecution_allowed�	tree_node�dynamic_params_depthr)�function_value�param_index�inf�allowed��func��Sc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/dynamic_params.py�wrapper&s
  28  �	$�z"_avoid_recursions.<locals>.wrapperr)rrrrr�_avoid_recursions%s
  29  rcs��jjstS�j}�����}|durt|�rtS|jdkr)t|�}|dur(tSn|j	j
  30  }tjd|dd����}t
  31  |||�}t���fdd�|D��}tjddd�|S)	a:
  32      A dynamic search for param values. If you try to complete a type:
  33  
  34      >>> def func(foo):
  35      ...     foo
  36      >>> func(1)
  37      >>> func("")
  38  
  39      It is not known what the type ``foo`` without analysing the whole code. You
  40      have to look for all calls to ``func`` to find out what ``foo`` possibly
  41      is.
  42      NZlambdefzDynamic param search in %s.ZMAGENTA)�colorc3s"�|]}t�|����VqdS)N)r�infer)�.0�	arguments�rrrr�	<genexpr>\s����
  43  �z'dynamic_param_lookup.<locals>.<genexpr>zDynamic param result finished)rZdo_dynamic_params_searchrr�get_root_contextZ
  44  py__file__r�type�_get_lambda_name�name�valuerZdbg�_search_function_argumentsrZ	from_sets)rr�funcdef�path�string_name�module_contextZarguments_list�valuesrr"r�dynamic_param_lookup6s(
  45  ��r/N)�defaultccs��|}|dkrt|�}|jdkr|jj}|}d}d}|j}tjr*t||g|dd�}n|g}|D]5}	t|	|�D](\}
  46  }|d7}||j	t
  47  krIdS|	�|
  48  �}t||||
  49  |�D]}
  50  d	}|
  51  VqVq6|rddSq/dS)
  52  z(
  53      Returns a list of param names.
  54      �__init__�classdefFr�)Zlimit_reductionrNT)
  55  rr%r'r(rrZ dynamic_params_for_other_modulesr
  56  �_get_potential_nodesr�MAX_PARAM_SEARCHES�create_context�_check_name_for_execution)r-r*r,�compare_node�clsZfound_arguments�irZmodule_contextsZfor_mod_contextr'�trailer�random_contextr!rrrr)fs@�
  57  �
  58  
  59  ����r)cCsD|j}|jdkr t|��d�}|dkr |jd}|jdkr |jSdS)NZ	expr_stmt�=rr')�parentr%�nextZyield_operators�childrenr()�node�stmtZfirst_operator�firstrrrr&�s
  60  
  61  
  62  r&ccsb�z	|j��|}Wn
  63  tyYdSw|D]}|��}|j}|jdkr.|dkr.||fVqdS)Nr;�()rZget_used_names�KeyErrorZ
  64  get_next_leafr>r%)Zmodule_valueZfunc_string_name�namesr'Zbracketr;rrrr4�s��
  65  ��r4c#s�ddlm}���fdd�}���|�D]o}|j}||kr$||�Vqt|j|�r�|jdkr�|j��}	t|	�dkr;q|	d��}
  66  dd�|
  67  D�|gkr���	�}|�
  68  ||��}t||	dj�}
  69  |
  70  D]#\}�|j
  71  |j
  72  krq|jkr�nq`|�|�}t�|||��EdHq`qdS)	Nr)�BaseFunctionExecutionContextcsp�jd}|dkrd}t��|��}ddlm}|jjdkr,t��|j||�}|||�S|�	�r6||j|�}|S)Nr�)r)�InstanceArgumentsr2)
  73  r@rZjedi.inference.value.instancerIrr%r
  74  ZTreeInstance�parent_contextZis_bound_method)r(Zarglist�argsrIZcreated_instance��contextrr;rr�create_args�s 
  75  �
  76  z._check_name_for_execution.<locals>.create_argsr*rcSsg|]}|j�qSr)r)r �vrrr�
  77  <listcomp>�sz-_check_name_for_execution.<locals>.<listcomp>)Zjedi.inference.value.functionrGrr�
  78  isinstancerJr%Zget_param_names�lenr$Z
  79  as_contextr4r,�	start_pos�end_posr6r7)rrMr8r'r;rGrNr(Z
  80  value_nodeZparam_namesr.r-Zexecution_contextZpotential_nodesr<rrLrr7�s:�
  81  
  82  
  83  
  84  ���r7)!�__doc__ZjedirrZjedi.parser_utilsrZjedi.inference.cacherZjedi.inference.argumentsrZjedi.inference.paramrZjedi.inference.helpersrZjedi.inference.utilsr	Zjedi.inference.valuer
  85  Zjedi.inference.base_valuerrZjedi.inference.referencesr
  86  Zjedi.inferencerr5rZincrease_indentr/r)r&r4r7rrrr�<module>s0..
  87