a
    Š©lcÎ  ã                   @   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 q4q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   úQ/var/www/html/django/DPS/env/lib/python3.9/site-packages/jedi/inference/finder.pyÚfilter_name   s    
r   c                 c   s<   | D ]2}|j d ur0|j  ¡ }|d ur0|jdkr0q|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ˆ ƒr˜ˆ  ¡ }z| ¡ |j }W n tyD   Y dS 0 t‡ ‡fdd„|D ƒƒ}|D ]4}t|dƒ}|durbt	| |j
|ƒ}|durb|  S qbˆ jdv rædd„ ˆ jddd… D ƒ}	t|	ƒD ] }
|j|
jkrÄt	| |
|ƒ  S qÄ|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 q|‘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   ó    é   é   )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   s0    	ÿ


r)   c                 C   sV   | j dv rRt| jƒdkrR| j\}}|j dkrR|jdkrR|j dkrR|jd dkrR|S d S )N)ÚpowerÚ	atom_expré   r   r	   Útrailerr   ú()r   Úlenr&   r
   )ÚnodeÚfirstr-   r   r   r   Ú_get_isinstance_trailer_arglist]   s    
ÿÿr2   c                 C   s  d }t |ƒ}|d ur¤t|jƒdkr¤|jd }t| j| ||ƒ}t| ¡ ƒ}t|ƒdkr¤t|jƒdkr¤|\\}}	\}
}|d u r¤|
d u r¤t|ƒ}t|jd ƒ}||kr¤|}|d u r°d S t}| 	¡ D ]F}t
|tjƒrö|jdkrö| ¡ D ]}|| 	¡  ¡ O }qÞq¼|| ¡ O }q¼|S )Né   r!   r,   r   Útuple)r2   r/   r&   r   Zinference_stater   ÚunpackÚ_get_call_stringr   Zinferr	   r   ÚSequenceZ
array_typeZ
py__iter__Zexecute_with_values)r
   r0   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   sN   | j jdkrt| j ƒS d}|  ¡ }|  ¡ j}|j|k rJ||j7 }| ¡ }q,|S )Nr+   Ú )	Úparentr   r6   Zget_first_leafZget_last_leafr   r   r
   Zget_next_leaf)r0   ÚcodeÚleafÚendr   r   r   r6   ˆ   s    




r6   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)   r2   r%   r6   r   r   r   r   Ú<module>   s   
(
!