o
    Zh                     @   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   R/var/www/html/lang_env/lib/python3.10/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