o
    Zh                     @   s   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
 Zdd Zdd Zdd Zdd Zdd ZdS )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                 C   s@   t |tr|jn|}g }| D ]}||}|r nq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)filtersZname_or_strZstring_namenamesfilter r   L/var/www/html/lang_env/lib/python3.10/site-packages/jedi/inference/finder.pyfilter_name   s   
r   c                 c   s>    | D ]}|j d ur|j  }|d ur|jdkrq|V  qd S )NZdel_stmt)Z	tree_nameZget_definitiontype)r   nameZ
definitionr   r   r   r   +   s   

r   c                    s   t jsdS d}t rL  }z	| |j }W n
 ty"   Y dS w t fdd|D }|D ]}t|d}|durKt	| |j
|}|durK|  S q1 jdv rsdd  jddd D }	t|	D ]}
|j|
jkrrt	| |
|  S qb|S )	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.
    Nc                    s2   g | ]} j |j   krp jk rn n|qS r   )	start_posend_pos).0nflowposr   r   
<listcomp>I   s
    "z*check_flow_information.<locals>.<listcomp>Zassert_stmt)Zif_stmtZ
while_stmtc                 S   s   g | ]}|d kr|qS ):r   )r   cr   r   r   r   V   s          )r   Zdynamic_flow_informationr   Zget_root_nodeZget_used_namesr
   KeyErrorreversedr   _check_isinstance_typeZ	assertionr   childrenr   r   )r
   r   search_namer   resultZmodule_noder   r   ZassZpotential_ifsZif_testr   r   r   check_flow_information5   s6   	

r(   c                 C   sV   | j dv r)t| jdkr)| j\}}|j dkr)|jdkr)|j dkr)|jd dkr)|S d S )N)power	atom_expr   r   r	   trailerr   ()r   lenr%   r
   )nodefirstr,   r   r   r   _get_isinstance_trailer_arglist]   s   
r1   c                 C   s  d }t |}|d urRt|jdkrR|jd }t| j| ||}t| }t|dkrRt|jdkrR|\\}}	\}
}|d u rR|
d u rRt|}t|jd }||krR|}|d u rXd S t}|	 D ]#}t
|tjr{|jdkr{| D ]
}||	  O }qoq^|| O }q^|S )N   r    r+   r   tuple)r1   r.   r%   r   Zinference_stater   unpack_get_call_stringr   Zinferr	   r   SequenceZ
array_typeZ
py__iter__Zexecute_with_values)r
   r/   r&   Zlazy_clsr,   ZarglistargsZ
param_listkey1_key2Zlazy_value_clscallZis_instance_callZ	value_setZ
cls_or_tupZ
lazy_valuer   r   r   r$   g   s.   
r$   c                 C   sV   | j jdkrt| j S d}|  }|  j}|j|k r)||j7 }| }|j|k s|S )Nr*    )	parentr   r5   Zget_first_leafZget_last_leafr   r   r
   Zget_next_leaf)r/   codeleafendr   r   r   r5      s   




r5   N)__doc__Z
parso.treer   Zparso.python.treer   Zjedir   Zjedi.inference.argumentsr   Zjedi.inference.valuer   Zjedi.inference.base_valuer   Zjedi.parser_utilsr   r   r   r(   r1   r$   r5   r   r   r   r   <module>   s    
(
!