Format: application/x-python-code
⬇ Download File (4.3 KB)
   1  o
   2  
   3  �h��@s�dZddlmZddlmZddlmZddlmZddl	m
   4  Z
   5  ddlmZddl
   6  mZd	d
   7  �Zdd�Zd
   8  d�Zdd�Zdd�Zdd�ZdS)a�
   9  Searching for names with given scope and name. This is very central in Jedi and
  10  Python. The name resolution is quite complicated with descripter,
  11  ``__getattribute__``, ``__getattr__``, ``global``, etc.
  12  
  13  If you want to understand name resolution, please read the first few chapters
  14  in http://blog.ionelmc.ro/2015/02/09/understanding-python-metaclasses/.
  15  
  16  Flow checks
  17  +++++++++++
  18  
  19  Flow checks are not really mature. There's only a check for ``isinstance``.  It
  20  would check whether a flow has the form of ``if isinstance(a, type_or_tuple)``.
  21  Unfortunately every other thing is being ignored (e.g. a == '' would be easy to
  22  check for -> a is a string). There's big potential in these checks.
  23  �)�search_ancestor)�Name)�settings)�
  24  TreeArguments)�iterable)�	NO_VALUES)�is_scopecCs@t|t�r|jn|}g}|D]}|�|�}|rnqtt|��S)zh
  25      Searches names that are defined in a scope (the different
  26      ``filters``), until a name fits.
  27      )�
  28  isinstancer�value�get�list�_remove_del_stmt)�filtersZname_or_strZstring_name�names�filter�r�Kc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/finder.py�filter_names
  29  �rccs>�|D]}|jdur|j��}|dur|jdkrq|VqdS)NZdel_stmt)Z	tree_nameZget_definition�type)r�nameZ
  30  definitionrrrr
  31  +s�
  32  
  33  �r
  34  cs�tjsdSd}t��rL���}z	|��|j}Wn
  35  ty"YdSwt��fdd�|D��}|D]}t|d�}|durKt	||j
  36  |�}|durK|Sq1�jdvrsdd��jddd�D�}	t|	�D]}
  37  |j
  38  |
  39  jkrrt	||
  40  |�Sqb|S)	z� Try to find out the type of a variable just with the information that
  41      is given by the flows: e.g. It is also responsible for assert checks.::
  42  
  43          if isinstance(k, str):
  44              k.  # <- completion here
  45  
  46      ensures that `k` is a string.
  47      Ncs2g|]}�j|jkr�p�jkrnn|�qSr)�	start_pos�end_pos)�.0�n��flow�posrr�
  48  <listcomp>Is
  49  "�z*check_flow_information.<locals>.<listcomp>Zassert_stmt)Zif_stmtZ
  50  while_stmtcSsg|]}|dkr|�qS)�:r)r�crrrrVs��)rZdynamic_flow_informationrZ
  51  get_root_nodeZget_used_namesr
  52  �KeyError�reversedr�_check_isinstance_typeZ	assertionr�childrenrr)r
  53  r�search_namer�resultZmodule_noderrZassZ
  54  potential_ifsZif_testrrr�check_flow_information5s6	��
  55  �
  56  �r(cCsV|jdvr)t|j�dkr)|j\}}|jdkr)|jdkr)|jdkr)|jddkr)|SdS)N)�power�	atom_expr�rr	�trailerr�()r�lenr%r
  57  )�node�firstr,rrr�_get_isinstance_trailer_arglist]s
  58  r1cCsd}t|�}|durRt|j�dkrR|jd}t|j|||�}t|���}t|�dkrRt|j�dkrR|\\}}	\}
  59  }|durR|
  60  durRt|�}t|jd�}
  61  ||
  62  krR|}|durXdSt}|�	�D]#}t
  63  |tj�r{|j
  64  dkr{|��D]
  65  }||�	���O}qoq^||��O}q^|S)N�r r+r�tuple)r1r.r%rZinference_stater�unpack�_get_call_stringrZinferr	r�SequenceZ
  66  array_typeZ
  67  py__iter__Zexecute_with_values)r
  68  r/r&Zlazy_clsr,Zarglist�argsZ
  69  param_list�key1�_�key2Zlazy_value_cls�callZis_instance_callZ	value_setZ
  70  cls_or_tupZ
  71  lazy_valuerrrr$gs.
  72  �r$cCsV|jjdkrt|j�Sd}|��}|��j}|j|kr)||j7}|��}|j|ks|S)Nr*�)	�parentrr5Zget_first_leafZ
  73  get_last_leafrrr
  74  Z
  75  get_next_leaf)r/�code�leaf�endrrrr5�s
  76  
  77  
  78  
  79  
  80  �r5N)�__doc__Z
  81  parso.treerZparso.python.treerZjedirZjedi.inference.argumentsrZjedi.inference.valuerZjedi.inference.base_valuerZjedi.parser_utilsrrr
  82  r(r1r$r5rrrr�<module>s
  83  (
  84  !