o
    MThI                     @   s  d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlZd dl	Z	d dl
Z
d dlZd dlmZ d dlmZmZ d dlmZ eeeeeefZeejZejejejejej ej!ej"ej#ej$ej%ej&eej'ej(ej)fZ*eejZee+j,Z-ej.d /e0Z1ee1d Z2e0 Z3ej4ej5ej6ej7ej8ej9ej:ej;dZ<ej=ej>d	Z?e?@e< ejej!ej#ee-e2eAeBfZCe3fd
dZDeddZEdd ZFdd ZGdd ZHG dd dZIdeIfddZJdd ZKG dd dZLdd ZMdS )    N)
namedtuple)Path)OptionalTuple)getattr_static__dict____subclasshook__)z==z!=iszis not<z<=>z>=)+-c                 C   sL   z	t | |\}}W n ty   |tu r | Y S w t|tr$t| |S |S N)r   AttributeError	_sentinel
isinstanceALLOWED_DESCRIPTOR_ACCESSgetattr)objnamedefaultattris_get_descriptor r   a/home/air/segue/gemini/backup/venv/lib/python3.10/site-packages/jedi/inference/compiled/access.pysafe_getattrN   s   

r   SignatureParamz]name has_default default default_string has_annotation annotation annotation_string kind_namec                    s    fdd}|S )Nc                    s(    | }t |dkr|d d d }|S )N2   z..)len)selfrfuncr   r   wrapperi   s   zshorten_repr.<locals>.wrapperr   )r"   r#   r   r!   r   shorten_reprh   s   r$   c                 C   s   | j |S r   )compiled_subprocessget_or_create_access_handle)inference_stater   r   r   r   create_accessq      r(   c                 C   s   t j|}t _z?zt| W n3 ty(   tjd||f tdd Y W |t _d S  tyA   tjdt	  tdd Y W |t _d S w W |t _n|t _w t j
| }t| |S )Nz$Module %s not importable in path %s.   )
stacklevelzCannot import:
%s)syspath
__import__ImportErrorwarningswarnUserWarning	Exception	traceback
format_excmodulescreate_access_path)r'   dotted_namesys_pathtempmoduler   r   r   load_moduleu   s,   

	


r<   c                   @   s   e Zd Zdd ZdS )
AccessPathc                 C   s
   || _ d S r   )accessesr   r>   r   r   r   __init__      
zAccessPath.__init__N)__name__
__module____qualname__r@   r   r   r   r   r=      s    r=   returnc                 C   s   t | |}t| S r   )r(   r=   get_access_path_tuples)r'   r   accessr   r   r   r7      s   
r7   c                 C   sL   t | rdS t | rdS t | s"t | s"t | s"t | r$dS dS )Nclassr;   functioninstance)inspectisclassismodule	isbuiltinismethodismethoddescriptor
isfunctionr   r   r   r   get_api_type   s   

rS   c                   @   s  e Zd Zdd Zdd Zdd Zde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ddZdd Zdd Zdd Zd d! Zed"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 ZdWdee e e	e f fd4d5Z!e"fd6d7Z#d8d9 Z$d:d; Z%d<d= Z&d>d? Z'd@dA Z(dBdC Z)dDdE Z*dFdG Z+dHdI Z,dJdK Z-dLdM Z.dNdO Z/de	e fdPdQZ0dRdS Z1dTdU Z2dVS )XDirectObjectAccessc                 C   s   || _ || _d S r   )_inference_state_obj)r   r'   r   r   r   r   r@      s   
zDirectObjectAccess.__init__c                 C   s   d| j j|  f S )Nz%s(%s))	__class__rB   get_reprr   r   r   r   __repr__      zDirectObjectAccess.__repr__c                 C      t | j|S r   r(   rU   r   r   r   r   r   _create_access   r)   z!DirectObjectAccess._create_accessrE   c                 C   r\   r   )r7   rU   r^   r   r   r   _create_access_path   r)   z&DirectObjectAccess._create_access_pathc                 C   
   t | jS r   )boolrV   rY   r   r   r   
py__bool__   rA   zDirectObjectAccess.py__bool__c                 C   s$   zt | jjW S  ty   Y d S w r   )r   rV   __file__r   rY   r   r   r   
py__file__   s
   zDirectObjectAccess.py__file__c                 C   s   t | jpdS )N )rK   getdocrV   rY   r   r   r   	py__doc__   s   zDirectObjectAccess.py__doc__c                 C   s^   t | jrt| jr| j}nz| jj}W n
 ty   Y d S w z|jW S  ty.   Y d S w r   )_is_class_instancerV   rK   rP   rW   r   rB   )r   clsr   r   r   
py__name__   s   

zDirectObjectAccess.py__name__c                    s"   t  fdd jjdd  D S )Nc                 3       | ]}  |V  qd S r   r`   ).0rj   rY   r   r   	<genexpr>       z7DirectObjectAccess.py__mro__accesses.<locals>.<genexpr>   )tuplerV   __mro__rY   r   rY   r   py__mro__accesses   s   "z$DirectObjectAccess.py__mro__accessesc                    s   t  jtr fdd j D S t  jttfr$ fdd jD S   r4t j jj	}|
 S z jj}W n
 tyD   Y d S w t j| }|d urT|gS d S )Nc                       g | ]}  |qS r   rm   rn   vrY   r   r   
<listcomp>       z>DirectObjectAccess.py__getitem__all_values.<locals>.<listcomp>c                    ru   r   rm   rv   rY   r   r   rx      ry   )r   rV   dictvalueslistrr   is_instancerT   rU   rW   py__getitem__all_values__getitem__r   get_return_annotation)r   rj   getitem
annotationr   rY   r   r~      s"   z*DirectObjectAccess.py__getitem__all_valuesT)safec                C   s&   |rt | jtvrd S | | j| S r   )typerV   ALLOWED_GETITEM_TYPESr`   )r   indexr   r   r   r   py__simple_getitem__   s   z'DirectObjectAccess.py__simple_getitem__c                 C   s   z| j j}W n
 ty   Y d S w t| j| }|d ur |gS t| j tvr)g S g }t| j D ]\}}|dkr; |S |	| 
| q0|S )N   )rV   __iter__r   rT   rU   r   r   r   	enumerateappendr`   )r   iter_methodplstipartr   r   r   py__iter__list   s"   z!DirectObjectAccess.py__iter__listc                 C   s   |  | jjS r   )r`   rV   rW   rY   r   r   r   py__class__     zDirectObjectAccess.py__class__c                    s    fdd j jD S )Nc                    ru   r   rm   )rn   baserY   r   r   rx   
  ry   z2DirectObjectAccess.py__bases__.<locals>.<listcomp>)rV   	__bases__rY   r   rY   r   py__bases__	     zDirectObjectAccess.py__bases__c                 C   s2   t | jdd }t|trtdd |D sd S |S )N__path__c                 s   s    | ]}t |tV  qd S r   )r   strrn   r   r   r   r   ro     rp   z0DirectObjectAccess.py__path__.<locals>.<genexpr>)r   rV   r   r|   all)r   pathsr   r   r   
py__path__  s   
zDirectObjectAccess.py__path__c                 C   sz   t | jrt| jS t| jddddkrt| jS t| j}|tkr)t| jS t|ddddkr7t| jS t| jS )NrC   rf   r   builtins)rK   rM   rV   reprr   r   rZ   object)r   type_r   r   r   rX     s   



zDirectObjectAccess.get_reprc                 C      t | jS r   )rK   rL   rV   rY   r   r   r   is_class&  r)   zDirectObjectAccess.is_classc                 C   s   t | jpt | jS r   )rK   rQ   rV   rO   rY   r   r   r   is_function)  s   zDirectObjectAccess.is_functionc                 C   r   r   )rK   rM   rV   rY   r   r   r   	is_module,  r)   zDirectObjectAccess.is_modulec                 C   ra   r   )ri   rV   rY   r   r   r   r}   /  rA   zDirectObjectAccess.is_instancec                 C   r   r   )rK   rP   rV   rY   r   r   r   rP   2  r)   z%DirectObjectAccess.ismethoddescriptorc                 C   sN   dd }|   r
dS || j}|d u r |t| j}|d u r dS t|dS )Nc                 S   s   t | dt | dd S )NrD   rB   )r   rR   r   r   r   try_to_get_name6  r[   z?DirectObjectAccess.get_qualified_names.<locals>.try_to_get_namer   .)r   rV   r   rr   split)r   r   r   r   r   r   get_qualified_names5  s   
z&DirectObjectAccess.get_qualified_namesc                 C   ra   r   )dirrV   rY   r   r   r   r   B  rA   zDirectObjectAccess.dirc                 C   s&   zt | j W dS  ty   Y dS w )NTF)iterrV   	TypeErrorrY   r   r   r   has_iterE  s   
zDirectObjectAccess.has_iterc                 C   s   z
t | j|\}}W nF tyP   |sMtjdd, td zt| j|dd fW W  d     Y S  ty;   Y nw W d    Y dS 1 sHw   Y  Y dS w |rtt|t	vrtt
|trrt|jdrrt| j|j}dd| fS dS dS )	NTrecordalwaysF)FFN__annotations__)TTN)TFN)r   rV   r   r0   catch_warningssimplefilterhasattrr3   r   r   r   propertyfgetrT   rU   r   )r   r   r   r   r   ar   r   r   is_allowed_getattrL  s2   


z%DirectObjectAccess.is_allowed_getattrc              
   C   s,  z#t jdd t d t| j|}W d    n1 sw   Y  W n  tyC } z|tu r7t|tr5 t|}W Y d }~nd }~ww | 	|}t
|rQ|gS z|j}W n	 ty_   Y nw |d uryt|tryzt| W n	 tyx   Y nw t
|}|d u rt
t|}|d u rt}| 	||gS )NTr   r   )r0   r   r   r   rV   r3   r   r   r   r_   rK   rM   rC   r   r.   r/   	getmoduler   r   )r   r   r   
return_objerG   r;   r   r   r   getattr_pathsl  sD   





z DirectObjectAccess.getattr_pathsc                 C   s<   t | jttttttfv s| jd u r| jS tdt | j )Nz Object is type %s and not simple)	r   rV   rb   bytesfloatintr   slice
ValueErrorrY   r   r   r   get_safe_value  s   $z!DirectObjectAccess.get_safe_valuec                 C   ra   r   )rS   rV   rY   r   r   r   rS     rA   zDirectObjectAccess.get_api_typec                 C   s   t | jtrdS d S )Nrz   )r   rV   rz   rY   r   r   r   get_array_type  s   z!DirectObjectAccess.get_array_typec                    s     fdd} fdd| D S )Nc                  3   s2    t  j D ]\} }| dkr d S |V  qd S )Nr   )r   rV   keys)r   krY   r   r   iter_partial_keys  s   z;DirectObjectAccess.get_key_paths.<locals>.iter_partial_keysc                    ru   r   rm   )rn   r   rY   r   r   rx     ry   z4DirectObjectAccess.get_key_paths.<locals>.<listcomp>r   )r   r   r   rY   r   get_key_paths  s   	z DirectObjectAccess.get_key_pathsc                    s$    fdd   D }dd |D S )Nc                    s   g | ]}t  j|qS r   r]   )rn   orY   r   r   rx         z=DirectObjectAccess.get_access_path_tuples.<locals>.<listcomp>c                 S   s   g | ]}|  |fqS r   )rk   )rn   rG   r   r   r   rx     r   )_get_objects_pathr?   r   rY   r   rF     s   z)DirectObjectAccess.get_access_path_tuplesc                    s    fdd}t tt | S )Nc                  3   s     j } | V  z| j} W n	 ty   Y nw | V  z| j}W n ty3   t| s0tV  Y d S Y d S w |d u r=tV  d S z	tj| V  W d S  t	yS   tV  Y d S w r   )
rV   __objclass__r   rC   rK   rM   r   r,   r6   KeyError)r   imp_plzrY   r   r   get  s.   



z1DirectObjectAccess._get_objects_path.<locals>.get)r|   reversed)r   r   r   rY   r   r     s   z$DirectObjectAccess._get_objects_pathc                 C   s"   |j }t| }| || j|jS r   )rG   
_OPERATORSr`   rV   )r   other_access_handleoperatorother_accessopr   r   r   execute_operation  s   z$DirectObjectAccess.execute_operationc                    s   d}d}t  jddddkr8tdt j}|dur8|d}d	dl}tjd
kr0|	 j}nt  jddd}|t
 fdd|D fS )zF
        Returns Tuple[Optional[str], Tuple[AccessPath, ...]]
        Nr   rC   rf   r   typingztyping.(\w+)\[rq   r   )      __args__c                 3   rl   r   rm   )rn   argrY   r   r   ro     rp   zBDirectObjectAccess.get_annotation_name_and_args.<locals>.<genexpr>)r   rV   rematchr   groupr   r,   version_infoget_argsrr   )r   r   argsmr   r   rY   r   get_annotation_name_and_args  s   

z/DirectObjectAccess.get_annotation_name_and_argsc                 C   s   t | jo
| jtkS r   )rK   rL   rV   r   rY   r   r   r   needs_type_completions  r   z)DirectObjectAccess.needs_type_completionsc                 C   s
   t |S r   )rK   formatannotation)r   r   r   r   r   _annotation_to_str  rA   z%DirectObjectAccess._annotation_to_strc                    s    fdd   j D S )Nc                    sZ   g | ])}t |j|j|ju |jt|j|j|ju |j |jt|j	d qS ))r   has_defaultr   default_stringhas_annotationr   annotation_string	kind_name)
r   r   r   emptyr`   r   r   r   r   kindr   rY   r   r   rx     s    





z;DirectObjectAccess.get_signature_params.<locals>.<listcomp>)_get_signature
parametersr{   rY   r   rY   r   get_signature_params  s   

z'DirectObjectAccess.get_signature_paramsc              	   C   s*   | j }zt|W S  ttfy   tw r   )rV   rK   	signatureRuntimeErrorr   r   r^   r   r   r   r      s   z!DirectObjectAccess._get_signaturec                 C   sh   z	| j jd}W n
 ty   Y d S w |d u rd S zt| j d}W n	 ty.   Y nw | |S )NrE   )rV   r   r   r   r   get_type_hintsr3   r`   )r   r   r   r   r   r   
  s   
z(DirectObjectAccess.get_return_annotationc                 C   s   |  | j S r   )r`   rV   rY   r   r   r   negate  r   zDirectObjectAccess.negatec                    s&   t  fdd  D }  |fS )zw
        Used to return a couple of infos that are needed when accessing the sub
        objects of an objects
        c                 3   s    | ]
}|  |fV  qd S r   )r   )rn   r   rY   r   r   ro   "  s
    
z3DirectObjectAccess.get_dir_infos.<locals>.<genexpr>)rz   r   r   )r   tuplesr   rY   r   get_dir_infos  s   z DirectObjectAccess.get_dir_infosN)T)3rB   rC   rD   r@   rZ   r_   r=   r`   rc   r   r   re   rh   rk   rt   r~   r   r   r   r   r   r$   rX   r   r   r   r}   rP   r   r   r   r   rb   r   r   r   r   rS   r   r   rF   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rT      sV    	
 -
rT   c                 C   s>   z| j }W n
 ty   Y dS w |tkot|tot|t S )zLike inspect.* methods.F)rW   r   r   r   
issubclassNOT_CLASS_TYPES)r   rj   r   r   r   ri   )  s   
ri   )NrK   typesr4   r,   r   r   collectionsr   r0   r   r   r   pathlibr   r   r   &jedi.inference.compiled.getattr_staticr   r   r|   rr   r   	bytearrayrz   r   r   replaceMethodDescriptorTypeBuiltinFunctionTypeCodeType	FrameTypeFunctionTypeGeneratorTypeGetSetDescriptorType
LambdaTypeMemberDescriptorType
MethodType
ModuleTypeTracebackTypeMappingProxyTypeSimpleNamespaceDynamicClassAttributer   setr   WrapperDescriptorTyper   __get__r   object_class_dictClassMethodDescriptorTyper   eqneis_is_notltlegtgeCOMPARISON_OPERATORSaddsubr   updatestaticmethodclassmethodr   r   r   r$   r(   r<   r=   r7   rS   rT   ri   r   r   r   r   <module>   s    



	   