o
    ï›h7  ã                   @   sÐ   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 dd„ Z
dd„ Zd$d
d„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZG dd„ deƒZedd„ ƒZd%dd„Zd d!„ Zd"d#„ ZdS )&é    N)Úchain)Úcontextmanager)Útreec                 C   sJ   | j }d|v sd|v rdS tj tjdd¡}tt t 	|¡d t
| ƒ¡ƒS )Nzdist-packageszsite-packagesFÚlibÚpythonz\d.\d)ÚpartsÚosÚpathÚjoinÚsysÚprefixÚboolÚreÚmatchÚescapeÚstr)r	   r   Ú	base_path© r   úLc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/helpers.pyÚis_stdlib_path   s
   r   c                 C   sZ   t   | ¡}g }| jD ]}t|tjƒrt   |¡}||_nt|ƒ}||_| |¡ q
||_|S )zO
    Much, much faster than copy.deepcopy, but just for parser tree nodes.
    )ÚcopyÚchildrenÚ
isinstancer   ZLeafÚparentÚdeep_ast_copyÚappend)ÚobjZnew_objZnew_childrenÚchildÚ	new_childr   r   r   r      s   


r   Fc                 C   sL  |j }|jdkrddlm} | | j¡S |jdks%||jd |jd fvr@|dkr1ddlm} |S |jdkr;|  	|¡S |  	|¡S |j }|j 
|¡}|rN|}n|d	 }|jd
krt|}		 |	d	8 }	|j|	 }
|
jdkrinqZ|j|	d	 |… }n|jd }
|jd	|… }|
dkrŽ|d }
|d	d… }|  	|
¡}ddlm} |D ]}|| ||ƒ}q›|S )a®  
    Creates a "call" node that consist of all ``trailer`` and ``power``
    objects.  E.g. if you call it with ``append``::

        list([]).append(3) or None

    You would get a node with the content ``list([]).append`` back.

    This generates a copy of the original ast node.

    If you're using the leaf, e.g. the bracket `)` it will return ``list([])``.

    We use this function for two purposes. Given an expression ``bar.foo``,
    we may want to
      - infer the type of ``foo`` to offer completions after foo
      - infer the type of ``bar`` to be able to jump to the definition of foo
    The option ``cut_own_trailer`` must be set to true for the second purpose.
    Zfstringr   )ÚcompiledÚtraileréÿÿÿÿú:)Ú	NO_VALUESZatomé   Z
error_nodeTÚawaitN)Úinfer_trailer)r   ÚtypeZjedi.inferencer   Zget_string_value_setÚinference_stater   Zjedi.inference.base_valuer#   Z
infer_nodeÚindexZjedi.inference.syntax_treer&   )ÚcontextÚleafZcut_own_trailerr    r   r#   Úpowerr)   ÚcutÚstartÚbaseZtrailersÚvaluesr&   r   r   r   Úinfer_call_of_leaf-   sF   
"





ü

r1   c                 C   sN   z| j }W n ty   | jdkr| g Y S g  Y S w tt dd„ |D ƒ¡ƒS )NÚnamec                 s   s   � | ]}t |ƒV  qd S ©N)Úget_names_of_node)Ú.0Úcr   r   r   Ú	<genexpr>x   s   € z$get_names_of_node.<locals>.<genexpr>)r   ÚAttributeErrorr'   Úlistr   Úfrom_iterable)Únoder   r   r   r   r4   o   s   


ür4   c                 C   s   |   ¡ ot| jd d�tƒS ©N)Údefault)Zis_compiledr   Úget_safe_valuer   ©Úvaluer   r   r   Ú	is_string{   s   rA   c                 C   s   t | ƒpt| ƒS r3   )Ú	is_numberrA   r?   r   r   r   Ú
is_literal   s   rC   c                 C   s   | j d d�} t| |ƒr| S d S r<   )r>   r   )r@   Úacceptr   r   r   Ú_get_safe_value_or_noneƒ   s   
ÿrE   c                 C   ó
   t | tƒS r3   )rE   Úintr?   r   r   r   Úget_int_or_none‰   ó   
rH   c                 C   rF   r3   )rE   r   r?   r   r   r   Úget_str_or_none�   rI   rJ   c                 C   s   t | ttfƒd uS r3   )rE   rG   Úfloatr?   r   r   r   rB   ‘   s   rB   c                   @   s   e Zd ZdS )ÚSimpleGetItemNotFoundN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   rL   •   s    rL   c               
   g   s0   � zd V  W d S  | y } zt |ƒ‚d }~ww r3   )rL   )Zexception_classesÚer   r   r   Úreraise_getitem_errors™   s   €€ÿrQ   c                 C   sÂ   d}g }| dd … D ]R}|dv r|s|t |jƒ7 }q
|jdkr;|jd d d… D ]}| |¡ ||u r4 nq'q
 ||fS |jdkrO| |¡ ||u rN ||fS q
|dkrX|sWg }q
 ||fS ||fS )Nr   r$   )Ú.z...Zdotted_nameé   r2   ú,)Úlenr@   r'   r   r   )ÚnodesZis_import_fromZ
until_nodeÚlevelÚnamesr;   Únr   r   r   Úparse_dotted_names¡   s8   €

ÿ
õ
÷€rZ   c                 G   s   |   |d d… ¡ |d ¡S )Nr!   )Úimport_moduleZpy__getattribute__)r(   rX   r   r   r   Úvalues_from_qualified_names¾   s   r\   c                 C   s"   |   ¡ j}|d u rdS |d dv S )NFr   )ZpandasÚnumpyZ
tensorflowZ
matplotlib)Zget_root_contextÚstring_names)r*   r^   r   r   r   Úis_big_annoying_libraryÂ   s   
r_   )Fr3   )r   r   r   r   Ú	itertoolsr   Ú
contextlibr   Zparso.pythonr   r   r   r1   r4   rA   rC   rE   rH   rJ   rB   Ú	ExceptionrL   rQ   rZ   r\   r_   r   r   r   r   Ú<module>   s.    
B

