o
    ð›hn,  ã                   @   sL  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„ deƒZ$G dd„ dee!ƒZ%G dd„ de e%ƒZ&G dd„ deƒZ'G dd„ dej(ƒZ)eƒ dd„ ƒZ*dd„ Z+dd„ Z,eƒ d 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                       s‚   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zeed�d	d
„ ƒZ	e
fdd„Zedd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡  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                    s   t ƒ  |¡ || _|j| _d S ©N)ÚsuperÚ__init__Úcompiled_valueÚaccess_handle)Úselfr   Ú
tree_value©Ú	__class__© úSc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/compiled/mixed.pyr   ,   s   zMixedObject.__init__c                 o   s   � t | j| j| jƒV  d S r   )ÚMixedObjectFilterÚinference_stater   Ú_wrapped_value©r   ÚargsÚkwargsr   r   r    Úget_filters1   s   €
ÿzMixedObject.get_filtersc                 C   ó
   | j  ¡ S r   )r   Úget_signatures©r   r   r   r    r)   5   s   
zMixedObject.get_signatures)Údefaultc                 C   s   t | jƒ}|s
| j}| |¡S r   )r   r#   Ú
py__call__)r   Ú	argumentsÚvaluesr   r   r    r,   :   s   

zMixedObject.py__call__c                 C   s   |t u r	| j ¡ S | j |¡S r   )Ú	_sentinelr   Úget_safe_value)r   r+   r   r   r    r0   B   s   
zMixedObject.get_safe_valuec                 C   ó   | j jS r   )r   Ú
array_typer*   r   r   r    r2   H   ó   zMixedObject.array_typec                 C   r(   r   )r   Úget_key_valuesr*   r   r   r    r4   L   ó   
zMixedObject.get_key_valuesc                 C   s0   | 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_objectr   r   r    r9   O   s   z MixedObject.py__simple_getitem__c                 C   r(   r   )r   Únegater*   r   r   r    r<   U   r5   zMixedObject.negatec                 C   s   | j d u r	t| ƒS t| ƒS r   )Zparent_contextÚMixedModuleContextÚMixedContextr*   r   r   r    Ú_as_contextX   s   
zMixedObject._as_contextc                 C   s   dt | ƒj| j ¡ | jf S )Nz<%s: %s; %s>)r8   Ú__name__r   Zget_reprr#   r*   r   r   r    Ú__repr__]   s
   ýzMixedObject.__repr__)r@   Ú
__module__Ú__qualname__Ú__doc__r   r'   r)   r   r   r,   r/   r0   Úpropertyr2   r4   r9   r<   r?   rA   Ú__classcell__r   r   r   r    r      s    

r   c                   @   s   e Zd Zedd„ ƒZdS )r>   c                 C   r1   r   )Ú_valuer   r*   r   r   r    r   f   r3   zMixedContext.compiled_valueN)r@   rB   rC   rE   r   r   r   r   r    r>   e   s    r>   c                   @   s   e Zd ZdS )r=   N)r@   rB   rC   r   r   r   r    r=   k   s    r=   c                       s8   e Zd ZdZ‡ fdd„Zedd„ ƒZedd„ ƒZ‡  Z	S )Ú	MixedNamezB
    The ``CompiledName._compiled_value`` is our MixedObject.
    c                    s   t ƒ  |¡ || _d S r   )r   r   Ú_parent_tree_value)r   Zwrapped_nameZparent_tree_valuer   r   r    r   s   s   
zMixedName.__init__c                 C   s    t |  ¡ ƒ}|s
dS |d jjS )N)r   r   r   )ÚlistÚinferÚnameÚ	start_pos)r   r.   r   r   r    rM   w   s   zMixedName.start_posc                    s`   | j  ¡ ‰ | j}| ¡ s| ¡ r%| | j¡}ˆ  ¡ r%t‡ fdd„|D ƒƒS | 	¡ }t
| jˆ |ƒS )Nc                    s   h | ]}t ˆ |ƒ’qS r   ©r   )Ú.0Úv©r   r   r    Ú	<setcomp>†   s    z"MixedName.infer.<locals>.<setcomp>)Z_wrapped_nameZinfer_compiled_valuerI   Zis_instanceÚis_classZpy__getattribute__Zstring_nameZis_functionr	   Úget_root_contextÚ_createZ_inference_state)r   r   Útree_valuesÚmodule_contextr   rQ   r    rK      s   
zMixedName.infer)
r@   rB   rC   rD   r   rE   rM   r   rK   rF   r   r   r   r    rH   o   s    
rH   c                       s(   e Zd Z‡ fdd„Z‡ fdd„Z‡  ZS )r!   c                    s   t ƒ  ||¡ || _d S r   )r   r   Ú_tree_value)r   r"   r   r   r   r   r    r   �   s   
zMixedObjectFilter.__init__c                    s   t tƒ j|i |¤Ž| jƒS r   )rH   r   Ú_create_namerX   r$   r   r   r    rY   ‘   s   þzMixedObjectFilter._create_name)r@   rB   rC   r   rY   rF   r   r   r   r    r!   Œ   s    r!   c                 C   s   | j |dtjtjd� ¡ S )NT)ÚpathÚcacheZ
diff_cacheÚ
cache_path)Úparser   Zfast_parserZcache_directoryZget_root_node)r"   rZ   r   r   r    Ú_load_module˜   s   üûr^   c                 C   sˆ   zt  | ¡} W n	 ty   Y nw t  | ¡s4t  | ¡s4t  | ¡s4t  | ¡s4t  | ¡s4t  | ¡s4t  	| ¡r6| S z| j
W S  tyC   t‚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;   r   r   r    Ú_get_object_to_check¢   s0   þ
ÿþýüûúÿrk   c              	      sx  |}zt |ƒ}t |¡}W n ttfy   Y d S w |d u r d nt|ƒ}z|d u s-| ¡ s0W d S W n
 ty;   Y d S w t|ƒ}t| |ƒ}t 	|¡rVt
| j|ƒ}||||fS z|j}W n
 tye   Y d S w |dkrld S | ¡  |g ¡}dd„ |D ƒ}|sd S z|j}	|	j‰ W n	 ty�   Y nw ‡ fdd„|D ƒ}
|
rž|
}t
| j|ƒ}|d j}|jdkr¶t|ƒdkr¶d S ||||fS )Nz<lambda>c                 S   s(   g | ]}|j jd v r|j j|kr|‘qS ))ÚfuncdefÚclassdef)Úparentr8   rL   )rO   Únr   r   r    Ú
<listcomp>å   s
    ÿz*_find_syntax_node_name.<locals>.<listcomp>c                    s   g | ]}|j d  ˆ kr|‘qS )r   )rM   )rO   rL   ©Zline_nrr   r    rp   ö   s    éÿÿÿÿrl   Úinstance)rk   r_   ÚgetsourcefileÚOSErrorrj   r   Úexistsr   r^   rb   r   Zgrammarr@   ri   Zget_used_namesÚgetÚ__code__Úco_firstlinenorn   r8   r   )r"   r;   Zoriginal_objectrZ   Úfile_ioÚmodule_nodeÚ
code_linesZname_strÚnamesÚcodeZ
line_namesÚ	tree_noder   rq   r    Ú_find_syntax_node_name¹   s^   þþû


þÿ
ÿ
r€   c                    s  ˆ j jj}t| |ƒ}|d u r(t|ƒtttfv rtˆ hƒS t	ˆ ƒ}|s'tˆ hƒS nS|\}}}}	|d u s7|j
|krfˆ  ¡  ¡ }
|
 ¡ }t| d¡ƒ}t| ||||	|
 ¡ d�}|d urb| j |t|gƒ¡ | ¡ }t| |¡hƒ}|jdkr{ˆ  ¡ s{| ¡ }t‡ fdd„|D ƒƒS )NÚ.)rz   Ústring_namesr|   Ú
is_packagerm   c                 3   s   � | ]	}t ˆ |d �V  qdS ))r   NrN   )rO   r   rQ   r   r    Ú	<genexpr>2  s
   € 
ÿ
ÿz_create.<locals>.<genexpr>)r   r6   r7   r€   r8   ÚdictrJ   Útupler	   r   r   rT   Ú	get_valueZ
py__name__Úsplitr   rƒ   Zmodule_cacheÚaddZ
as_contextZcreate_valuerS   Zexecute_with_values)r"   r   rW   r;   ÚresultrV   r{   r   rz   r|   Zroot_compiled_valuerL   r‚   Zmodule_valuer   rQ   r    rU     s>   



ÿû
þrU   ).rD   r_   Úpathlibr   Zjedi.parser_utilsr   Zjedir   Z
jedi.cacher   Zjedi.inferencer   Zjedi.file_ior   Zjedi.inference.namesr   Zjedi.inference.base_valuer	   r
   r   Zjedi.inference.valuer   Zjedi.inference.cacher   r   Zjedi.inference.compiled.accessr   r   Z!jedi.inference.gradual.conversionr   Zjedi.inference.contextr   r   r   Úobjectr/   r   r>   r=   rH   ZCompiledValueFilterr!   r^   rk   r€   rU   r   r   r   r    Ú<module>   s6    J
	R