o
    ï›hÎ  ã                   @   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   úKc:\Users\shubh\Videos\agent\nova\Lib\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    
(
!