
    Mh                         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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                     t          |t                    r|j        n|}g }| D ]}|                    |          }|r 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        U/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jedi/inference/finder.pyfilter_namer      sp    
 (2+t'D'DU+##+KE  

;'' 	E	  ''(((    c              #   x   K   | D ]4}|j         '|j                                         }||j        dk    r0|V  5d S )Ndel_stmt)	tree_nameget_definitiontype)r   name
definitions      r   r   r   +   sZ        >%6688J%*/Z*G*G



 r   c                 "   t           j        sdS d}t                    r                                }	 |                                |j                 }n# t          $ r Y dS w xY wt          fd|D                       }|D ]0}t          |d          }|t          | |j
        |          }||c S 1j        dv rOd j        ddd         D             }	t          |	          D ]%}
|j        |
j        k    rt          | |
|          c S &|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                 V    g | ]%}j         |j         cxk    rpj        k      n n|&S  )	start_posend_pos).0nflowposs     r   
<listcomp>z*check_flow_information.<locals>.<listcomp>I   sP     
 
 
~DDDD0Ct|DDDDD DDDr   assert_stmt)if_stmt
while_stmtc                     g | ]
}|d k    |S ):r!   )r$   cs     r   r(   z*check_flow_information.<locals>.<listcomp>V   s    DDDq188888r         )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_tests    ` `       r   check_flow_informationr?   5   sw    , tF~~ "((**	..001BCEE 	 	 	44	 
 
 
 
 

 
 
  
  	" 	"D!$66C/s}kRR%!MMMy---DDDM!$Q$$7DDD.. 	K 	KG$w66-eWkJJJJJ 7Ms   A 
A%$A%c                     | j         dv rVt          | 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   lenr8   r   )nodefirstrD   s      r   _get_isinstance_trailer_arglistrI   ]   sq    y***s4=/A/AQ/F/Fw:EK<$?$?LI--'2B12E2L2LN4r   c                    d }t          |          }|t          |j                  dk    r|j        d         }t          | j        | ||          }t          |                                          }t          |          dk    rXt          |j                  dk    r@|\  \  }}	\  }
}|3|
1t          |          }t          |j        d                   }||k    r|}|d S t          }|	                                D ]}t          |t          j                  rL|j        dk    rA|                                D ]+}||	                                                                z  },h||                                z  }|S )N   r/   rC   r   tuple)rI   rF   r8   r   inference_stater   unpack_get_call_stringr   inferr   r   Sequence
array_type
py__iter__execute_with_values)r   rG   r9   lazy_clsrD   arglistargs
param_listkey1_key2lazy_value_clscallis_instance_call	value_set
cls_or_tup
lazy_values                    r   r6   r6   g   s   H-d33Gs7#34499"1%U2E7GLL$++--((
z??aC(8$9$9Q$>$>0:-IT1-n|'44#3G4DQ4G#H#H  +++-HtInn&& : :
j("344 	:9NRY9Y9Y(3355 F F
Z--//CCEEE		F 77999IIr   c                    | j         j        dk    rt          | j                   S d}|                                 }|                                 j        }|j        |k     r)||j        z  }|                                }|j        |k     )|S )NrB    )	parentr   rO   get_first_leafget_last_leafr#   r"   r   get_next_leaf)rG   codeleafends       r   rO   rO      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?   rI   r6   rO   r!   r   r   <module>rs      s    " ' & & & & & " " " " " "       2 2 2 2 2 2 ) ) ) ) ) ) / / / / / / & & & & & &) ) )  % % %P    B
 
 
 
 
r   