a
    ÷£Be¶  ã                   @   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   ú^/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/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.infer)N)Ú__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   ÚnamesZ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   sN   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   s   dS )NTr   ©r   r   r   r   Ú	is_moduleM   s    zModuleMixin.is_modulec                 C   s   dS )NFr   r6   r   r   r   Úis_stubP   s    zModuleMixin.is_stubc                 C   s   |   | | jd ¡S ©Néÿÿÿÿ)Ú_module_name_classÚstring_namesr6   r   r   r   r+   S   s    zModuleMixin.namec                    sF   g d¢}t ‡ fdd„|D ƒƒ}ˆ  ¡ }|d urBtˆ dt|ƒƒ|d< |S )N)Ú__package__r$   r!   c                 3   s   | ]}|t ˆ |ƒfV  qd S r   )r   )Ú.0Únr6   r   r   Ú	<genexpr>\   ó    z6ModuleMixin._module_attributes_dict.<locals>.<genexpr>Ú__file__)ÚdictÚ
py__file__r   Ústr)r   r*   ÚdctÚpathr   r6   r   r/   X   s    z#ModuleMixin._module_attributes_dictc                 c   s2   |   ¡ D ]$}t| ¡ d ƒ}|d us&J ‚|V  qd S r   )Ústar_importsÚnextr1   )r   Zstar_moduleÚfr   r   r   r0   b   s    zModuleMixin.iter_star_filtersc                 C   s|   ddl m} g }|  ¡ }| j ¡ D ]T}| ¡ r"|| j| ¡ d ||jd� 	¡ }|D ]}t
|tƒrR|| ¡ 7 }qR||7 }q"|S )Nr   )ÚImporterr:   )Zimport_pathÚmodule_contextÚlevel)Zjedi.inference.importsrK   r)   Ú	tree_nodeZiter_importsZis_star_importr   Ú	get_pathsrM   ÚfollowÚ
isinstanceÚModuleValuerH   )r   rK   ÚmodulesrL   ÚiÚnewÚmoduler   r   r   rH   k   s     
ü


zModuleMixin.star_importsc                 C   s   dS )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   r6   r   r   r   Úget_qualified_names€   s    zModuleMixin.get_qualified_names)N)r!   r"   r#   r   r;   r1   r5   r7   r8   Úpropertyr   r+   r/   r0   rH   rW   r   r   r   r   r-   :   s   

		
r-   c                       sp   e Zd ZdZd‡ fdd„	Z‡ fdd„Zdd	„ Zee d
œdd„Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )rR   rV   NFc                    sF   t ƒ j|d |d� || _|d u r(d | _n|j| _|| _|| _|| _d S )N)r   rN   )Úsuperr   Úfile_ioÚ_pathrG   r<   Ú
code_linesÚ_is_package)r   r   Zmodule_noder\   rZ   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[   ÚsuffixrY   r8   r6   r^   r   r   r8   œ   s    zModuleValue.is_stubc                 C   s   | j d u rd S d | j ¡S )NÚ.)r<   Újoinr6   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[   Úabsoluter6   r   r   r   rD   ©   s    
zModuleValue.py__file__c                 C   s   | j S r   )r]   r6   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 r9   )r<   r]   r6   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 r„tƒ }| j ¡ D ],}tj || jj	¡}tj 
|¡rJ| |¡ qJ|r„t|ƒS |  ¡ }|dus˜J ‚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]   rb   r\   Úsetr   Zget_sys_pathÚosrG   r+   r   ÚisdirÚaddÚlistrD   Ú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   r6   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   )r_   r!   rc   rN   Ú	start_posÚend_posr8   r6   r   r   r   Ú__repr__á   s
    ýzModuleValue.__repr__)NNF)r!   r"   r#   r%   r   r8   rc   r   r   rD   r'   rf   r(   rt   rw   Ú__classcell__r   r   r^   r   rR   ‰   s     ÿ	!rR   )rk   Ú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-   rR   r   r   r   r   Ú<module>   s    O