
    ^j                         d dl Z d dlmZ d dlmZmZ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 erd dlmZ  G d de
      Z G d d      Z G d de      Z  G d de e      Z!y)    N)Path)OptionalTYPE_CHECKINGAny)inference_state_method_cache)AbstractNameDefinition
ModuleName)GlobalNameFilterParserTreeFilter
DictFilterMergedFilter)compiled)	TreeValue)SubModuleName)values_from_qualified_names)create_simple_object)ValueSetModuleContext)InferenceStatec                   "    e Zd ZdZdZddZd Zy)_ModuleAttributeNamezA
    For module attributes like __file__, __str__ and so on.
    instanceNc                 .    || _         || _        || _        y N)parent_contextstring_name_string_value)selfparent_moduler   string_values       T/opt/ringagent/.cad-venv/lib/python3.12/site-packages/jedi/inference/value/module.py__init__z_ModuleAttributeName.__init__   s    +&)    c                     | j                   6| j                   }t        t        | j                  j                  |      g      S t        j                  | j                  j                        S r   )r   r   r   r   inference_stater   get_string_value_set)r   ss     r"   inferz_ModuleAttributeName.infer   s`    )""A$T%8%8%H%H!L   ,,T-@-@-P-PQQr$   r   )__name__
__module____qualname____doc__api_typer#   r)    r$   r"   r   r      s     H*
Rr$   r   c                   P    e Zd ZU ded<   eed<   eed<   eed<    e       d        Zy)SubModuleDictMixinr   r&   
is_package
py__path__
as_contextc                     i }| j                         rW| j                  j                  j                  | j	                               }|D ]  }t        | j                         |      ||<   ! |S )zf
        Lists modules in the directory of this module (if this module is a
        package).
        )r2   r&   compiled_subprocessiter_module_namesr3   r   r4   )r   namesmodsnames       r"   sub_modules_dictz#SubModuleDictMixin.sub_modules_dict.   sj     ??'';;MM!D  E+DOO,=tDdE r$   N)r*   r+   r,   __annotations__r   r   r;   r/   r$   r"   r1   r1   (   s,    %%OOO!# $r$   r1   c                       e Zd ZU eZeed<   eed<   eed<   eed<   ddZd Zd Z	d	 Z
e e       d
               Z e       d        Zd Z eg       d        Zd Zy)ModuleMixin	tree_nodestring_namesr;   
py__file__Nc              #   (  K   t        t        | j                         |      t        | j                                      t	        | j                                t	        | j                                | j                         E d {    y 7 w)N)r   origin_scope)r   r   r4   r
   r   r;   _module_attributes_dictiter_star_filters)r   rC   s     r"   get_filterszModuleMixin.get_filtersI   su     #0) T__./
 	
 ..01155788))+++s   BB
BBc                 8    t        | j                  dd      \  }|S )Ntypes
ModuleType)r   r&   )r   cs     r"   py__class__zModuleMixin.py__class__U   s    ()=)=wUr$   c                      y)NTr/   r   s    r"   	is_modulezModuleMixin.is_moduleY   s    r$   c                      y)NFr/   rM   s    r"   is_stubzModuleMixin.is_stub\   s    r$   c                 @    | j                  | | j                  d         S N)_module_name_classr@   rM   s    r"   r:   zModuleMixin.name_   s"     &&tT->->r-BCCr$   c                      g d}t         fd|D              } j                         }|t         dt        |            |d<   |S )N)__package__r-   r*   c              3   :   K   | ]  }|t        |      f  y wr   )r   ).0nr   s     r"   	<genexpr>z6ModuleMixin._module_attributes_dict.<locals>.<genexpr>h   s     E!A+D!45Es   __file__)dictrA   r   str)r   r8   dctpaths   `   r"   rD   z#ModuleMixin._module_attributes_dictd   sE    6EuEE 24SYOC
O
r$   c              #   z   K   | j                         D ]$  }t        |j                         d       }|J | & y wr   )star_importsnextrF   )r   star_modulefs      r"   rE   zModuleMixin.iter_star_filtersn   sB     ,,. 	K[,,.5A= =G	s   9;c                 t   ddl m} g }| j                         }| j                  j	                         D ]  }|j                         s || j                  |j                         d   ||j                        j                         }|D ]&  }t        |t              s||j                         z  }( ||z  } |S )Nr   )ImporterrS   )import_pathmodule_contextlevel)jedi.inference.importsrf   r4   r?   iter_importsis_star_importr&   	get_pathsri   follow
isinstanceModuleValuera   )r   rf   modulesrh   inewmodules          r"   ra   zModuleMixin.star_importsw   s    3*,,. 	A!(( !b 1#1''	
 &(  " 9F!&+66#6#6#889 3	 r$   c                      y)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/   rM   s    r"   get_qualified_nameszModuleMixin.get_qualified_names   s     r$   r   )r*   r+   r,   r	   rT   r   r<   rF   rK   rN   rP   propertyr   r:   rD   rE   ra   rv   r/   r$   r"   r>   r>   B   s    #NO
, !#D $ D "# $ ""% &(r$   r>   c                   l     e Zd ZdZ	 	 d	 d fdZ fdZd Zdee   fdZ	d Z
d Zd	 Zd
 Zd Z xZS )rp   rt   returnc                     t         |   |d |       || _        |d | _        n|j                  | _        || _        || _        || _        y )N)r   r?   )superr#   file_io_pathr_   r@   
code_lines_is_package)r   r&   module_noder~   r|   r@   r2   	__class__s          r"   r#   zModuleValue.__init__   sU    ! 	 	

 ?)-DJ DJ7C$%r$   c                 l    | j                   | j                   j                  dk(  ryt        |          S )Nz.pyiT)r}   suffixr{   rP   )r   r   s    r"   rP   zModuleValue.is_stub   s0    ::!djj&7&76&A w  r$   c                 R    | j                   y dj                  | j                         S )N.)r@   joinrM   s    r"   
py__name__zModuleValue.py__name__   s&    $xx))**r$   c                 P    | j                   y| j                   j                         S )z?
        In contrast to Python's __file__ can be None.
        N)r}   absoluterM   s    r"   rA   zModuleValue.py__file__   s$     ::zz""$$r$   c                     | j                   S r   )r   rM   s    r"   r2   zModuleValue.is_package   s    r$   c                 l    | j                   g S | j                  r| j                   S | j                   d d S rR   )r@   r   rM   s    r"   py__package__zModuleValue.py__package__   s;    $I$$$  "%%r$   c                    | j                   sydj                  | j                  dd       }d}|d   |v s|d   |v rt               }| j                  j                         D ]g  }t        j                  j                  || j                  j                        }t        j                  j                  |      sW|j                  |       i |rt        |      S | j                         }|J t        j                  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   r   r~   setr&   get_sys_pathosr_   r:   r   isdiraddlistrA   dirname)r   first_few_linesoptionspathsr(   otherfiles          r"   r3   zModuleValue.py__path__   s      ''$//#2"67 J1:(GAJ/,I EE))668 %Q		(=(=>77=='IIe$% E{"  %&&r$   c                     t        |       S r   r   rM   s    r"   _as_contextzModuleValue._as_context   s    T""r$   c                     d| j                   j                  d| j                         d| j                  j                  d   d| j                  j
                  d   d| j                         dS )N<z: @r   -z	 is_stub=>)r   r*   r   r?   	start_posend_posrP   rM   s    r"   __repr__zModuleValue.__repr__   sN    NN##T__%6NN$$Q')?)?)BLLN
 	
r$   )NNF)ry   N)r*   r+   r,   r.   r#   rP   r   r   r   rA   r2   r   r3   r   r   __classcell__)r   s   @r"   rp   rp      sO    HIM/4&9=& !+
%HTN % &'B#
r$   rp   )"r   pathlibr   typingr   r   r   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   r1   r>   rp   r/   r$   r"   <module>r      sq    	  / / = C _ _ # / . > 8 . 0-R1 R( 4P$ Pf]
+y ]
r$   