
    Mhn,                        d Z ddl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 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 ddlmZ ddlmZm Z m!Z!  e"            Z# G d de          Z$ G d dee!          Z% G d de e%          Z& G d de          Z' G d dej(                  Z) e            d             Z*d Z+d Z, e            d             Z-dS )z 
Used only for REPL Completion.
    N)Path)get_cached_code_lines)settings)memoize_method)compiled)FileIO)NameWrapper)ValueSetValueWrapper	NO_VALUES)ModuleValue)inference_state_function_cacheinference_state_method_cache)ALLOWED_GETITEM_TYPESget_api_type)to_stub)CompiledContextCompiledModuleContextTreeContextMixinc                        e Zd ZdZ fdZd Zd Z ee          d             Z	e
fdZed             Zd	 Zd
 Zd Zd Zd Z xZS )MixedObjecta  
    A ``MixedObject`` is used in two ways:

    1. It uses the default logic of ``parser.python.tree`` objects,
    2. except for getattr calls and signatures. The names dicts are generated
       in a fashion like ``CompiledValue``.

    This combined logic makes it possible to provide more powerful REPL
    completion. It allows side effects that are not noticable with the default
    parser structure to still be completable.

    The biggest difference from CompiledValue to MixedObject is that we are
    generally dealing with Python code and not with C code. This will generate
    fewer special cases, because we in Python you don't have the same freedoms
    to modify the runtime.
    c                 p    t                                          |           || _        |j        | _        d S N)super__init__compiled_valueaccess_handle)selfr   
tree_value	__class__s      ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jedi/inference/compiled/mixed.pyr   zMixedObject.__init__,   s4    $$$,+9    c              /   N   K   t          | j        | j        | j                  V  d S r   )MixedObjectFilterinference_stater   _wrapped_value)r   argskwargss      r!   get_filterszMixedObject.get_filters1   sC       $"5t7JL L 	L 	L 	L 	L 	Lr"   c                 4    | j                                         S r   )r   get_signaturesr   s    r!   r+   zMixedObject.get_signatures5   s     "11333r"   )defaultc                 f    t          | j                  }|s| j        }|                    |          S r   )r   r&   
py__call__)r   	argumentsvaluess      r!   r/   zMixedObject.py__call__:   s8     ,-- 	)(F  +++r"   c                 z    |t           u r| j                                        S | j                            |          S r   )	_sentinelr   get_safe_value)r   r-   s     r!   r4   zMixedObject.get_safe_valueB   s9    i&55777&55g>>>r"   c                     | j         j        S r   )r   
array_typer,   s    r!   r6   zMixedObject.array_typeH   s    "--r"   c                 4    | j                                         S r   )r   get_key_valuesr,   s    r!   r8   zMixedObject.get_key_valuesL   s    "11333r"   c                     | j         j        j        j        }t	          |          t
          v r| j                             |          S | j                            |          S r   )r   r   access_objtyper   py__simple_getitem__r&   )r   indexpython_objects      r!   r=   z MixedObject.py__simple_getitem__O   sU    +9@E"777&;;EBBB"77>>>r"   c                 4    | j                                         S r   )r   negater,   s    r!   rA   zMixedObject.negateU   s    "))+++r"   c                 L    | j         t          |           S t          |           S r   )parent_contextMixedModuleContextMixedContextr,   s    r!   _as_contextzMixedObject._as_contextX   s'    &%d+++D!!!r"   c                 v    dt          |           j        d| j                                        d| j        dS )N<z: z; >)r<   __name__r   get_reprr&   r,   s    r!   __repr__zMixedObject.__repr__]   sD     JJ''))))
 	
r"   )rJ   
__module____qualname____doc__r   r)   r+   r   r   r/   r3   r4   propertyr6   r8   r=   rA   rF   rL   __classcell__r    s   @r!   r   r      s         : : : : :
L L L4 4 4
 "!)444, , 54, &/ ? ? ? ? . . X.4 4 4? ? ?, , ," " "

 
 
 
 
 
 
r"   r   c                   $    e Zd Zed             ZdS )rE   c                     | j         j        S r   )_valuer   r,   s    r!   r   zMixedContext.compiled_valuef   s    {))r"   N)rJ   rM   rN   rP   r    r"   r!   rE   rE   e   s-        * * X* * *r"   rE   c                       e Zd ZdS )rD   N)rJ   rM   rN   rV   r"   r!   rD   rD   k   s        Dr"   rD   c                   N     e Zd ZdZ fdZed             Zed             Z xZ	S )	MixedNamezB
    The ``CompiledName._compiled_value`` is our MixedObject.
    c                 X    t                                          |           || _        d S r   )r   r   _parent_tree_value)r   wrapped_nameparent_tree_valuer    s      r!   r   zMixedName.__init__s   s)    &&&"3r"   c                 p    t          |                                           }|sdS |d         j        j        S )N)r   r   r   )listinfername	start_pos)r   r1   s     r!   rb   zMixedName.start_posw   s3    djjll## 	4ay~''r"   c                 z   | j                                         | j        }|                                s|                                rI|                    | j                  }                                rt          fd|D                       S |	                                }t          | j        |          S )Nc                 0    h | ]}t          |          S rV   r   ).0vr   s     r!   	<setcomp>z"MixedName.infer.<locals>.<setcomp>   s#     U U UA^Q!?!? U U Ur"   )_wrapped_nameinfer_compiled_valuer[   is_instanceis_classpy__getattribute__string_nameis_functionr
   get_root_context_create_inference_state)r   r   tree_valuesmodule_contextr   s       @r!   r`   zMixedName.infer   s    +@@BB,
!!## 	Wz':':'<'< 	W$778HIIK))++ W U U U U U U UVVV#4466t,nnMMMr"   )
rJ   rM   rN   rO   r   rP   rb   r   r`   rQ   rR   s   @r!   rY   rY   o   s         4 4 4 4 4 ( ( X( 	N 	N ^	N 	N 	N 	N 	Nr"   rY   c                   (     e Zd Z fdZ fdZ xZS )r$   c                 Z    t                                          ||           || _        d S r   )r   r   _tree_value)r   r%   r   r   r    s       r!   r   zMixedObjectFilter.__init__   s+    .999%r"   c                 \    t           t                      j        |i || j                  S r   )rY   r   _create_namerw   )r   r'   r(   r    s      r!   ry   zMixedObjectFilter._create_name   s4     EGG $1&11
 
 	
r"   )rJ   rM   rN   r   ry   rQ   rR   s   @r!   r$   r$      sQ        & & & & &
 
 
 
 
 
 
 
 
r"   r$   c                     |                      |dt          j        t          j                                                  S )NT)pathcache
diff_cache
cache_path)parser   fast_parsercache_directoryget_root_node)r%   r{   s     r!   _load_moduler      s<      '+	 !  
 moor"   c                    	 t          j        |           } n# t          $ r Y nw xY wt          j        |           sxt          j        |           sdt          j        |           sPt          j        |           s<t          j        |           s(t          j        |           st          j	        |           r| S 	 | j
        S # t          $ r t          w xY w)z9Check if inspect.getfile has a chance to find the source.)inspectunwrap
ValueErrorismoduleisclassismethod
isfunctionistracebackisframeiscoder    AttributeError	TypeError)r?   s    r!   _get_object_to_checkr      s    }55    	'' }--.. !-00 "=11	
 }-- ~m,, &&   s    
$$6B= =Cc                 B   |}	 t          |          }t          j        |          }n# t          t          f$ r Y d S w xY w|d nt          |          }	 ||                                sd S n# t          $ r Y d S w xY wt          |          }t          | |          }t          j	        |          rt          | j        |          }||||fS 	 |j        }n# t          $ r Y d S w xY w|dk    rd S |                                                    |g           }d |D             }|sd S 	 |j        }	|	j        fd|D             }
|
r|
}n# t          $ r Y nw xY wt          | j        |          }|d         j        }|j        dk    rt)          |          dk    rd S ||||fS )Nz<lambda>c                 N    g | ]"}|j         j        d v |j         j        |k     |#S ))funcdefclassdef)parentr<   ra   )rf   ns     r!   
<listcomp>z*_find_syntax_node_name.<locals>.<listcomp>   s@       8=3338J8J 	
8J8J8Jr"   c                 6    g | ]}|j         d          k    |S )r   )rb   )rf   ra   line_nrs     r!   r   z*_find_syntax_node_name.<locals>.<listcomp>   s*    MMMtq0AW0L0Ld0L0L0Lr"   r   instance)r   r   getsourcefileOSErrorr   r   existsr   r   r   r   grammarrJ   r   get_used_namesget__code__co_firstlinenor   r<   r   )r%   r?   original_objectr{   file_iomodule_node
code_linesname_strnamescode
line_names	tree_noder   s               @r!   _find_syntax_node_namer      sO   #O,];;$]33Y   tt <44T$ZZD	<t{{}}<4     
 tt TllG55K&& = +?+BDII
K*<< )   tt :t &&((,,Xr::E   E  t%
 % NMMMuMMM
  	E     ''>EEJ b	 I~""|O'D'D
'R'R t	7J66sB   #) >>A. .
A<;A<C 
C$#C$(E	 	
EEc           	         j         j        j        }t          | |          }|Vt	          |          t
          t          t          fv rt          h          S t                    }|st          h          S n,|\  }}}}	||j
        |k    r                                                                }
|
                                }t          |                    d                    }t          | ||||	|
                                          }|)| j                            |t          |g                     |                                }t          |                    |          h          }|j        dk    r(                                s|                                }t          fd|D                       S )N.)r   string_namesr   
is_packager   c              3   :   K   | ]}t          |           V  dS ))r   Nre   )rf   r   r   s     r!   	<genexpr>z_create.<locals>.<genexpr>2  sD         	Nz:::     r"   )r   r:   r;   r   r<   dictr_   tupler
   r   r   rp   	get_value
py__name__splitr   r   module_cacheadd
as_contextcreate_valuerl   execute_with_values)r%   r   rt   r?   resultrs   r   r   r   r   root_compiled_valuera   r   module_values    `            r!   rq   rq     s    #07<M#O]CCF~4u"555^,---n-- 	.^,---	. 7=3Y!^%=%L%L"0"A"A"C"C"M"M"O"O&1133D C11L&)%.99;;  L ,00x?W?WXXX)4466N ; ;I F FGHH>Z''!**,, @)==??    %     r"   ).rO   r   pathlibr   jedi.parser_utilsr   jedir   
jedi.cacher   jedi.inferencer   jedi.file_ior   jedi.inference.namesr	   jedi.inference.base_valuer
   r   r   jedi.inference.valuer   jedi.inference.cacher   r   jedi.inference.compiled.accessr   r   !jedi.inference.gradual.conversionr   jedi.inference.contextr   r   r   objectr3   r   rE   rD   rY   CompiledValueFilterr$   r   r   r   rq   rV   r"   r!   <module>r      s           3 3 3 3 3 3       % % % % % % # # # # # #       , , , , , , G G G G G G G G G G , , , , , ,! ! ! ! ! ! ! ! N N N N N N N N 5 5 5 5 5 5          FHH	G
 G
 G
 G
 G
, G
 G
 G
T* * * * *?$4 * * *	 	 	 	 	. 	 	 	N N N N N N N N:	
 	
 	
 	
 	
4 	
 	
 	
  !!  "!  .O7 O7 O7d  !!) ) "!) ) )r"   