o
    ð›h¶  ã                   @   sì   d dl Z d dlmZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZmZmZ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lmZ G dd„ deƒZG dd„ dƒZG dd„ deƒZG dd„ deeƒZdS )é    N)ÚPath)ÚOptional)Úinference_state_method_cache)ÚAbstractNameDefinitionÚ
ModuleName)ÚGlobalNameFilterÚParserTreeFilterÚ
DictFilterÚMergedFilter)Úcompiled)Ú	TreeValue)ÚSubModuleName)Úvalues_from_qualified_names)Úcreate_simple_object)ÚValueSet©ÚModuleContextc                   @   s&   e Zd ZdZdZddd„Zdd„ ZdS )	Ú_ModuleAttributeNamezA
    For module attributes like __file__, __str__ and so on.
    ÚinstanceNc                 C   s   || _ || _|| _d S ©N)Úparent_contextÚstring_nameÚ_string_value)ÚselfÚparent_moduler   Zstring_value© r   úQc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/value/module.pyÚ__init__   s   
z_ModuleAttributeName.__init__c                 C   s2   | j d ur| j }tt| jj|ƒgƒS t | jj¡S r   )r   r   r   r   Úinference_stater   Zget_string_value_set)r   Úsr   r   r   Úinfer   s   
ÿz_ModuleAttributeName.inferr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úapi_typer   r    r   r   r   r   r      s
    
r   c                   @   s   e Zd Zeƒ dd„ ƒZdS )ÚSubModuleDictMixinc                 C   s>   i }|   ¡ r| jj |  ¡ ¡}|D ]}t|  ¡ |ƒ||< q|S )zf
        Lists modules in the directory of this module (if this module is a
        package).
        )Ú
is_packager   Zcompiled_subprocessZiter_module_namesÚ
py__path__r   Ú
as_context)r   ÚnamesÚmodsÚnamer   r   r   Úsub_modules_dict&   s   ÿz#SubModuleDictMixin.sub_modules_dictN)r!   r"   r#   r   r-   r   r   r   r   r&   %   s    r&   c                   @   sr   e Zd ZeZddd„Zdd„ Zdd„ Zdd	„ Ze	e
ƒ d
d„ ƒƒZe
ƒ dd„ ƒZdd„ Ze
g ƒdd„ ƒZdd„ ZdS )ÚModuleMixinNc                 c   sP   � t t|  ¡ |d�t|  ¡ ƒƒV  t|  ¡ ƒV  t|  ¡ ƒV  |  ¡ E d H  d S )N)r   Úorigin_scope)r
   r   r)   r   r	   r-   Ú_module_attributes_dictÚiter_star_filters)r   r/   r   r   r   Úget_filters=   s   €þ
ûzModuleMixin.get_filtersc                 C   s   t | jddƒ\}|S )NÚtypesÚ
ModuleType)r   r   )r   Úcr   r   r   Úpy__class__I   s   zModuleMixin.py__class__c                 C   ó   dS )NTr   ©r   r   r   r   Ú	is_moduleM   ó   zModuleMixin.is_modulec                 C   r7   )NFr   r8   r   r   r   Úis_stubP   r:   zModuleMixin.is_stubc                 C   s   |   | | jd ¡S ©Néÿÿÿÿ)Ú_module_name_classÚstring_namesr8   r   r   r   r,   S   s   zModuleMixin.namec                    sF   g d¢}t ‡ fdd„|D ƒƒ}ˆ  ¡ }|d ur!tˆ dt|ƒƒ|d< |S )N)Ú__package__r$   r!   c                 3   s   � | ]
}|t ˆ |ƒfV  qd S r   )r   )Ú.0Únr8   r   r   Ú	<genexpr>\   s   € z6ModuleMixin._module_attributes_dict.<locals>.<genexpr>Ú__file__)ÚdictÚ
py__file__r   Ústr)r   r*   ÚdctÚpathr   r8   r   r0   X   s   z#ModuleMixin._module_attributes_dictc                 c   s4   � |   ¡ D ]}t| ¡ d ƒ}|d usJ ‚|V  qd S r   )Ústar_importsÚnextr2   )r   Zstar_moduleÚfr   r   r   r1   b   s   €ýzModuleMixin.iter_star_filtersc                 C   s|   ddl m} g }|  ¡ }| j ¡ D ]*}| ¡ r;|| j| ¡ d ||jd� 	¡ }|D ]}t
|tƒr6|| ¡ 7 }q)||7 }q|S )Nr   )ÚImporterr=   )Zimport_pathÚmodule_contextÚlevel)Zjedi.inference.importsrM   r)   Ú	tree_nodeZiter_importsZis_star_importr   Ú	get_pathsrO   ÚfollowÚ
isinstanceÚModuleValuerJ   )r   rM   ÚmodulesrN   ÚiÚnewÚmoduler   r   r   rJ   k   s(   
üû
€€zModuleMixin.star_importsc                 C   r7   )zØ
        A module doesn't have a qualified name, but it's important to note that
        it's reachable and not `None`. With this information we can add
        qualified names on top for all value children.
        r   r   r8   r   r   r   Úget_qualified_names€   s   zModuleMixin.get_qualified_namesr   )r!   r"   r#   r   r>   r2   r6   r9   r;   Úpropertyr   r,   r0   r1   rJ   rY   r   r   r   r   r.   :   s    

		
r.   c                       st   e Zd ZdZ		d‡ fdd„	Z‡ fdd„Zdd	„ Zd
ee fdd„Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )rT   rX   NFc                    sF   t ƒ j|d |d� || _|d u rd | _n|j| _|| _|| _|| _d S )N)r   rP   )Úsuperr   Úfile_ioÚ_pathrI   r?   Ú
code_linesÚ_is_package)r   r   Zmodule_noder^   r\   r?   r'   ©Ú	__class__r   r   r   Œ   s   ý
zModuleValue.__init__c                    s$   | j d ur| j jdkrdS tƒ  ¡ S )Nz.pyiT)r]   Úsuffixr[   r;   r8   r`   r   r   r;   œ   s   
zModuleValue.is_stubc                 C   s   | j d u rd S d | j ¡S )NÚ.)r?   Újoinr8   r   r   r   Ú
py__name__¤   s   
zModuleValue.py__name__Úreturnc                 C   s   | j du rdS | j  ¡ S )z?
        In contrast to Python's __file__ can be None.
        N)r]   Úabsoluter8   r   r   r   rF   ©   s   

zModuleValue.py__file__c                 C   s   | j S r   )r_   r8   r   r   r   r'   ²   s   zModuleValue.is_packagec                 C   s(   | j d u rg S | jr| j S | j d d… S r<   )r?   r_   r8   r   r   r   Úpy__package__µ   s
   
zModuleValue.py__package__c                 C   s¦   | j sdS d | jdd… ¡}d}|d |v s|d |v rBtƒ }| j ¡ D ]}tj || jj	¡}tj 
|¡r;| |¡ q%|rBt|ƒS |  ¡ }|dusLJ ‚tj |¡gS )z²
        In case of a package, this returns Python's __path__ attribute, which
        is a list of paths (strings).
        Returns None if the module is not a package.
        NÚ é2   )zdeclare_namespace(__name__)zextend_path(__path__r   é   )r_   rd   r^   Úsetr   Zget_sys_pathÚosrI   r,   r   ÚisdirÚaddÚlistrF   Údirname)r   Zfirst_few_linesÚoptionsÚpathsr   ÚotherÚfiler   r   r   r(   ½   s    
€zModuleValue.py__path__c                 C   s   t | ƒS r   r   r8   r   r   r   Ú_as_contextÞ   s   zModuleValue._as_contextc                 C   s.   d| j j|  ¡ | jjd | jjd |  ¡ f S )Nz<%s: %s@%s-%s is_stub=%s>r   )ra   r!   re   rP   Ú	start_posÚend_posr;   r8   r   r   r   Ú__repr__á   s
   ýzModuleValue.__repr__)NNF)r!   r"   r#   r%   r   r;   re   r   r   rF   r'   rh   r(   rv   ry   Ú__classcell__r   r   r`   r   rT   ‰   s    ÿ	!rT   )rm   Úpathlibr   Útypingr   Zjedi.inference.cacher   Zjedi.inference.namesr   r   Zjedi.inference.filtersr   r   r	   r
   Zjedi.inferencer   Zjedi.inference.base_valuer   r   Zjedi.inference.helpersr   Zjedi.inference.compiledr   r   Zjedi.inference.contextr   r   r&   r.   rT   r   r   r   r   Ú<module>   s"    O