o
    ˷e                     @   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)filtersname_or_strstring_namenamesfilter r   L/var/www/ideatree/venv/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 )Ndel_stmt)	tree_nameget_definitiontype)r   name
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>assert_stmt)if_stmt
while_stmtc                 S   s   g | ]}|d kr|qS ):r   )r   cr   r   r   r#   V   s          )r   dynamic_flow_informationr   get_root_nodeget_used_namesr
   KeyErrorreversedr   _check_isinstance_type	assertionr   childrenr   r   )r
   r!   search_namer"   resultmodule_noder   r   asspotential_ifsif_testr   r    r   check_flow_information5   s6   	

r9   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   lenr2   r
   )nodefirstr=   r   r   r   _get_isinstance_trailer_arglist]   s   
rB   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)rB   r?   r2   r   inference_stater   unpack_get_call_stringr   inferr	   r   Sequence
array_type
py__iter__execute_with_values)r
   r@   r3   lazy_clsr=   arglistargs
param_listkey1_key2lazy_value_clscallis_instance_call	value_set
cls_or_tup
lazy_valuer   r   r   r0   g   s.   
r0   c                 C   sV   | j jdkrt| j S d}|  }|  j}|j|k r)||j7 }| }|j|k s|S )Nr;    )	parentr   rG   get_first_leafget_last_leafr   r   r
   get_next_leaf)r@   codeleafendr   r   r   rG      s   




rG   N)__doc__
parso.treer   parso.python.treer   jedir   jedi.inference.argumentsr   jedi.inference.valuer   jedi.inference.base_valuer   jedi.parser_utilsr   r   r   r9   rB   r0   rG   r   r   r   r   <module>   s    
(
!