o
    ˷e                     @   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   string_value r   R/var/www/ideatree/venv/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   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   compiled_subprocess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   r1   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	   r1   _module_attributes_dictiter_star_filters)r   r3   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   r;   )NFr   r<   r   r   r   is_stubP   r>   zModuleMixin.is_stubc                 C   s   |  | | jd S N)_module_name_classstring_namesr<   r   r   r   r0   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nr<   r   r   	<genexpr>\   s    z6ModuleMixin._module_attributes_dict.<locals>.<genexpr>__file__)dict
py__file__r   str)r   r.   dctpathr   r<   r   r4   X   s   z#ModuleMixin._module_attributes_dictc                 c   s4    |   D ]}t| d }|d usJ |V  qd S r   )star_importsnextr6   )r   star_modulefr   r   r   r5   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   )ImporterrA   )import_pathmodule_contextlevel)jedi.inference.importsrR   r-   	tree_nodeiter_importsis_star_importr   	get_pathsrU   follow
isinstanceModuleValuerN   )r   rR   modulesrT   inewmoduler   r   r   rN   k   s(   

zModuleMixin.star_importsc                 C   r;   )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   r<   r   r   r   get_qualified_names   s   zModuleMixin.get_qualified_namesr   )r#   r$   r%   r   rB   r6   r:   r=   r?   propertyr   r0   r4   r5   rN   rb   r   r   r   r   r2   :   s    

		
r2   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 )r]   ra   NFc                    sF   t  j|d |d || _|d u rd | _n|j| _|| _|| _|| _d S )N)r   rW   )superr   file_io_pathrM   rC   
code_lines_is_package)r   r   module_noderg   re   rC   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)rf   suffixrd   r?   r<   rj   r   r   r?      s   
zModuleValue.is_stubc                 C   s   | j d u rd S d| j S )N.)rC   joinr<   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)rf   absoluter<   r   r   r   rJ      s   

zModuleValue.py__file__c                 C   s   | j S r   )rh   r<   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@   )rC   rh   r<   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      )rh   rn   rg   setr   get_sys_pathosrM   r0   r   isdiraddlistrJ   dirname)r   first_few_linesoptionspathsr!   otherfiler   r   r   r,      s    
zModuleValue.py__path__c                 C   s   t | S r   r   r<   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   )rk   r#   ro   rW   	start_posend_posr?   r<   r   r   r   __repr__   s
   zModuleValue.__repr__)NNF)r#   r$   r%   r'   r   r?   ro   r   r   rJ   r)   rr   r,   r   r   __classcell__r   r   rj   r   r]      s    	!r]   )rx   pathlibr   typingr   jedi.inference.cacher   jedi.inference.namesr   r   jedi.inference.filtersr   r   r	   r
   jedi.inferencer   jedi.inference.base_valuer   r   jedi.inference.helpersr   jedi.inference.compiledr   r   jedi.inference.contextr   r   r(   r2   r]   r   r   r   r   <module>   s"    O