
    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	 Zd
 Zd Zd Zd Zd Zy)a  
Searching for names with given scope and name. This is very central in Jedi and
Python. The name resolution is quite complicated with descripter,
``__getattribute__``, ``__getattr__``, ``global``, etc.

If you want to understand name resolution, please read the first few chapters
in http://blog.ionelmc.ro/2015/02/09/understanding-python-metaclasses/.

Flow checks
+++++++++++

Flow checks are not really mature. There's only a check for ``isinstance``.  It
would check whether a flow has the form of ``if isinstance(a, type_or_tuple)``.
Unfortunately every other thing is being ignored (e.g. a == '' would be easy to
check for -> a is a string). There's big potential in these checks.
    )search_ancestor)Name)settings)TreeArguments)iterable)	NO_VALUES)is_scopec                     t        |t              r|j                  n|}g }| D ]  }|j                  |      }|s n t	        t        |            S )zh
    Searches names that are defined in a scope (the different
    ``filters``), until a name fits.
    )
isinstancer   valuegetlist_remove_del_stmt)filtersname_or_strstring_namenamesfilters        P/var/www/cvtools/html/venv/lib/python3.12/site-packages/jedi/inference/finder.pyfilter_namer      sU    
 (2+t'D+##+KE 

;'
  '((    c              #      K   | D ]>  }|j                   ,|j                   j                         }||j                  dk(  r;| @ y w)Ndel_stmt)	tree_nameget_definitiontype)r   name
definitions      r   r   r   +   sJ      >>%668J%*//Z*G
s   AAc                    t         j                  syd}t        |      r|j                         }	 |j	                         |j
                     }t        |D cg c]4  }|j                  |j                  cxk  r|xs |j                  k  rn n|6 c}      }|D ].  }t        |d      }	|	t        | |	j                  |      }|,|c S  |j                  dv r]|j                  ddd   D 
cg c]
  }
|
dk7  s	|
 }}
t        |      D ]*  }|j                  |j                  kD  st        | ||      c S  |S # t        $ r Y yw xY wc c}w c c}
w )z Try to find out the type of a variable just with the information that
    is given by the flows: e.g. It is also responsible for assert checks.::

        if isinstance(k, str):
            k.  # <- completion here

    ensures that `k` is a string.
    Nassert_stmt)if_stmt
while_stmt      :)r   dynamic_flow_informationr	   get_root_nodeget_used_namesr   KeyErrorreversed	start_posend_posr   _check_isinstance_type	assertionr   children)r   flowsearch_nameposresultmodule_noder   nr   asscpotential_ifsif_tests                r   check_flow_informationr:   5   sZ    ,,F~((*	..01B1BCE 
~~D0Ct||D 
 
  	"D!$6C/s}}kR%!M	" yy--$(MM!$Q$$7Dq18DD. 	KG$$w6-eWkJJ	K M'  		
 Es#   D6 9E+
E
6E
6	EEc                     | j                   dv rht        | j                        dk(  rP| j                  \  }}|j                   dk(  r2|j                  dk(  r#|j                   dk(  r|j                  d   dk(  r|S y )N)power	atom_expr   r   r   trailerr   ()r   lenr/   r   )nodefirstr?   s      r   _get_isinstance_trailer_arglistrD   ]   si    yy**s4==/AQ/Fw::EKK<$?LLI-'2B2B12E2LNr   c                    d }t        |      }|t        |j                        dk(  r|j                  d   }t        | j                  | ||      }t        |j                               }t        |      dk(  rQt        |j                        dk(  r9|\  \  }}	\  }
}|,|
*t        |      }t        |j                  d         }||k(  r|}|y t        }|j                         D ]u  }t        |t        j                        rF|j                  dk(  r7|j                         D ]#  }||j                         j                         z  }% c||j                         z  }w |S )N   r#   r>   r   tuple)rD   rA   r/   r   inference_stater   unpack_get_call_stringr   inferr   r   Sequence
array_type
py__iter__execute_with_values)r   rB   r1   lazy_clsr?   arglistargs
param_listkey1_key2lazy_value_clscallis_instance_call	value_set
cls_or_tup
lazy_values                    r   r-   r-   g   s^   H-d3Gs7#3#349""1%U22E7GL$++-(
z?aC(8(8$9Q$>0:-IT1-n|'4#3G4D4DQ4G#H  ++-HInn& :
j("3"349N9NRY9Y(335 F
Z--/CCEE	F 7799I: r   c                 6   | j                   j                  dk(  rt        | j                         S d}| j                         }| j	                         j
                  }|j                  |k  r/||j                  z  }|j                         }|j                  |k  r/|S )Nr=    )	parentr   rJ   get_first_leafget_last_leafr,   r+   r   get_next_leaf)rB   codeleafends       r   rJ   rJ      s    {{;&,,D D




&
&C
..3


!!# ..3
 Kr   N)__doc__
parso.treer   parso.python.treer   jedir   jedi.inference.argumentsr   jedi.inference.valuer   jedi.inference.base_valuer   jedi.parser_utilsr	   r   r   r:   rD   r-   rJ    r   r   <module>ro      sA   " ' "  2 ) / &)%PB
r   