o
    ZhS                     @   s  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 ddlmZmZmZ ddl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%m&Z& G dd dZ'G dd deZ(G dd d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eZ-G d!d" d"eZ.G d#d$ d$eZ/d%d&d'd(d&d)Z0d*d+ Z1d,d- Z2d.d/ Z3d0d1 Z4e3e d2d3 Z5dS )4z$
Imitate the parser representation.
    N)partial)	Parameter)Path)Optional)debug)to_list)memoize_method)AbstractFilter)AbstractNameDefinitionValueNameMixinParamNameInterface)ValueValueSet	NO_VALUES)LazyKnownValue)	_sentinel)inference_state_function_cache)reraise_getitem_errors)BuiltinSignature)CompiledContextCompiledModuleContextc                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
CheckAttributezARaises :exc:`AttributeError` if the attribute X is not available.Nc                 C   s
   || _ d S N)
check_name)selfr    r   T/var/www/html/lang_env/lib/python3.10/site-packages/jedi/inference/compiled/value.py__init__      
zCheckAttribute.__init__c                 C   s$   || _ | jd u r|jdd  | _| S )N   )funcr   __name__)r   r    r   r   r   __call__   s   
zCheckAttribute.__call__c                 C   s&   |d u r| S |j | j t| j|S r   )access_handlegetattr_pathsr   r   r    )r   instanceownerr   r   r   __get__%   s   zCheckAttribute.__get__r   )r!   
__module____qualname____doc__r   r"   r'   r   r   r   r   r      s
    
r   c                       s~  e Zd ZdL fdd	Z fddZe dd Ze 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dd Zdd Zdd Zedd Zd d! Zd"d# Zed$d% Zed&d' ZdMd)d*Zed+d, Z fd-d.Z fd/d0ZdL fd1d2	Zd3d4 Zed5d6 Z d7d8 Z!e"fd9d:Z#d;d< Z$ fd=d>Z%d?d@ Z&dAdB Z'dCdD Z(edEdF Z)dGdH Z*dNdJdKZ+  Z,S )OCompiledValueNc                    s   t  || || _d S r   )superr   r#   )r   inference_stater#   parent_context	__class__r   r   r   /   s   
zCompiledValue.__init__c                    s   | j  }|d urt| j| S z| j d W n ty(   t | Y S w | j 	 r@ddl
m} t|| j| j| |gS t| |S )Nr"   r   )CompiledInstance)r#   Zget_return_annotationcreate_from_access_pathr-   execute_annotationr$   AttributeErrorr,   
py__call__is_classZjedi.inference.valuer1   r   r.   _execute_function)r   	argumentsreturn_annotationr1   r/   r   r   r5   3   s&   

zCompiledValue.py__call__c                 C      t | j| j S r   )r2   r-   r#   py__class__r   r   r   r   r;   H      zCompiledValue.py__class__c                    s"    ft  fdd j D  S )Nc                 3       | ]	}t  j|V  qd S r   r2   r-   .0accessr<   r   r   	<genexpr>N   
    

z*CompiledValue.py__mro__.<locals>.<genexpr>)tupler#   Zpy__mro__accessesr<   r   r<   r   	py__mro__L   s   
zCompiledValue.py__mro__c                    s   t  fdd j D S )Nc                 3   r>   r   r?   r@   r<   r   r   rC   U   rD   z,CompiledValue.py__bases__.<locals>.<genexpr>)rE   r#   py__bases__r<   r   r<   r   rG   S   s   zCompiledValue.py__bases__c                 C   
   | j  S r   )r#   get_qualified_namesr<   r   r   r   rI   Z      
z!CompiledValue.get_qualified_namesc                 C   rH   r   )r#   
py__bool__r<   r   r   r   rK   ]   rJ   zCompiledValue.py__bool__c                 C   rH   r   )r#   r6   r<   r   r   r   r6   `   rJ   zCompiledValue.is_classc                 C   rH   r   )r#   is_functionr<   r   r   r   rL   c   rJ   zCompiledValue.is_functionc                 C   rH   r   )r#   	is_moduler<   r   r   r   rM   f   rJ   zCompiledValue.is_modulec                 C      dS )NTr   r<   r   r   r   is_compiledi      zCompiledValue.is_compiledc                 C   rN   )NFr   r<   r   r   r   is_stubl   rP   zCompiledValue.is_stubc                 C   rH   r   )r#   is_instancer<   r   r   r   rR   o   rJ   zCompiledValue.is_instancec                 C   rH   r   )r#   	py__doc__r<   r   r   r   rS   r   rJ   zCompiledValue.py__doc__c           
      c   s    z| j  }W n; tyC   |  \}}|sg }n|d}| j  r*|dd |D ]}| d\}}}t	| ||V  q,Y d S w |D ]}	t
| |	V  qFd S )N,r   r   =)r#   Zget_signature_params
ValueError_parse_function_docsplitismethoddescriptorinsertstrip	partitionUnresolvableParamNameSignatureParamName)
r   Zsignature_params
params_strrettokenspname_defaultsignature_paramr   r   r   get_param_namesu   s$   

zCompiledValue.get_param_namesc                 C   s   |   \}}t| |gS r   )rW   r   )r   rd   Zreturn_stringr   r   r   get_signatures   s   zCompiledValue.get_signaturesc                 C   s   d| j j| j f S Nz<%s: %s>)r0   r!   r#   get_reprr<   r   r   r   __repr__   s   zCompiledValue.__repr__c                 C   s   |   }|d u r
dS t|S )N) rl   )rS   rW   )r   docr   r   r   rW      s   z!CompiledValue._parse_function_docc                 C   rH   r   )r#   Zget_api_typer<   r   r   r   api_type   r   zCompiledValue.api_typeFc                 c   s    |  |V  d S r   )_ensure_one_filter)r   rR   Zorigin_scoper   r   r   get_filters   s   zCompiledValue.get_filtersc                 C   s   t | j| |S r   )CompiledValueFilterr-   )r   rR   r   r   r   ro      s   z CompiledValue._ensure_one_filterc              	      s   t ttt, z| jj|| jj d}W n ty*   t	 | Y W  d    S w W d    n1 s5w   Y  |d u rDt	 |S t
t| j|gS N)safe)r   
IndexErrorKeyError	TypeErrorr#   py__simple_getitem__r-   allow_unsafe_executionsr4   r,   r   r2   )r   indexrB   r/   r   r   rw      s   
z"CompiledValue.py__simple_getitem__c                    s6    j  }|d u rt ||S t fdd|D S )Nc                 3   r>   r   r?   r@   r<   r   r   rC      rD   z.CompiledValue.py__getitem__.<locals>.<genexpr>)r#   Zpy__getitem__all_valuesr,   py__getitem__r   )r   Zindex_value_setcontextualized_nodeZall_access_pathsr/   r<   r   rz      s   
zCompiledValue.py__getitem__c                 #   sT    | j  st |E d H  | j  }|d u rd S |D ]}tt| j|V  qd S r   )r#   Zhas_iterr,   
py__iter__Zpy__iter__listr   r2   r-   )r   r{   Zaccess_path_listrB   r/   r   r   r|      s   

zCompiledValue.py__iter__c                 C   rH   r   )r#   
py__name__r<   r   r   r   r}      rJ   zCompiledValue.py__name__c                 C   s$   |   }|d u r| j }t| |S r   )r}   r#   rj   CompiledValueNamer   rc   r   r   r   rc      s   

zCompiledValue.namec              	   c   s    ddl m} ddlm} | jdkrd S |  d  D ]&}z
| jjj	
| W n	 ty1   Y qw || j|}| j||E d H  q|| E d H  d S )Nr   )
docstringsbuiltin_from_namefunction   )Zjedi.inferencer   jedi.inference.compiledr   rn   rW   rX   r-   builtins_moduler#   r$   r4   executeZinfer_return_types)r   paramsr   r   rc   Zbltn_objr   r   r   r7      s   
zCompiledValue._execute_functionc                 C   s.   z| j  W S  ty   |tkr | Y S w r   )r#   get_safe_valuerV   r   )r   re   r   r   r   r      s   zCompiledValue.get_safe_valuec                 C   s8   zt t| j| j|j|gW S  ty   t Y S w r   )r   r2   r-   r#   execute_operationrv   r   )r   otheroperatorr   r   r   r      s   
zCompiledValue.execute_operationc                    s   j  dkrtgS j  \}}fdd|D  |dkr*tdd  D S |r>t fddjj|D  S t	  S )NNonec                    s   g | ]}t t j|gqS r   )r   r2   r-   )rA   pathr<   r   r   
<listcomp>   s    z4CompiledValue.execute_annotation.<locals>.<listcomp>Unionc                 s   s    | ]}|  V  qd S r   )r3   )rA   argr   r   r   rC      s    z3CompiledValue.execute_annotation.<locals>.<genexpr>c                    s   g | ]}|  qS r   )Zwith_genericsrA   v)r8   r   r   r     s    )
r#   rj   r   Zget_annotation_name_and_argsZ	from_setsr-   Ztyping_moduleZpy__getattribute__r3   r,   )r   rc   argsr/   )r8   r   r   r3      s   


z CompiledValue.execute_annotationc                 C   r:   r   )r2   r-   r#   negater<   r   r   r   r   
     zCompiledValue.negatec                 C      t S r   r   r<   r   r   r   get_metaclasses  rP   zCompiledValue.get_metaclassesc                 C      t | S r   )r   r<   r   r   r   _as_context     zCompiledValue._as_contextc                 C   rH   r   )r#   Zget_array_typer<   r   r   r   
array_type  r   zCompiledValue.array_typec                    s    fdd j  D S )Nc                    s   g | ]}t  j|qS r   r?   )rA   kr<   r   r   r     s    
z0CompiledValue.get_key_values.<locals>.<listcomp>)r#   Zget_key_pathsr<   r   r<   r   get_key_values  s   
zCompiledValue.get_key_valuesTc                 C   s   | j  dv r	dS d S )N)r   z<class 'NoneType'>r   )r#   rj   )r   Zadd_class_infor   r   r   get_type_hint  s   zCompiledValue.get_type_hintr   )FN)T)-r!   r(   r)   r   r5   r   r;   rF   rG   rI   rK   r6   rL   rM   rO   rQ   rR   rS   r   rg   rh   rk   r   rW   propertyrn   rp   ro   rw   rz   r|   r}   rc   r7   r   r   r   r3   r   r   r   r   r   r   __classcell__r   r   r/   r   r+   .   s\    








	
r+   c                   @   sF   e Zd ZdZdd Zdd Zdd Zedd	 Zd
e	e
 fddZdS )CompiledModuleNc                 C   r   r   )r   r<   r   r   r   r   &  r   zCompiledModule._as_contextc                 C   rH   r   )r#   
py__path__r<   r   r   r   r   )  rJ   zCompiledModule.py__path__c                 C   s   |   d uS r   )r   r<   r   r   r   
is_package,     zCompiledModule.is_packagec                 C   s"   |   }|d u r
dS t|dS )Nr   .)r}   rE   rX   r   r   r   r   string_names/  s   zCompiledModule.string_namesreturnc                 C   rH   r   )r#   
py__file__r<   r   r   r   r   7  rJ   zCompiledModule.py__file__)r!   r(   r)   Zfile_ior   r   r   r   r   r   r   r   r   r   r   r   r   #  s    
r   c                   @   sT   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zedd Z	dd Z
edd ZdS )CompiledNamec                 C   s&   || _ | | _|| _|| _|| _d S r   )_inference_state
as_contextr.   _parent_valuestring_nameis_descriptor)r   r-   Zparent_valuerc   r   r   r   r   r   <  s
   

zCompiledName.__init__c                 C   s   |    S r   )infer_compiled_valuerS   r<   r   r   r   rS   C  r   zCompiledName.py__doc__c                 C   s"   | j  }|d u rd S || jf S r   )r.   rI   r   )r   Zparent_qualified_namesr   r   r   _get_qualified_namesF  s   
z!CompiledName._get_qualified_namesc                 C   s$   | j }| s| r| j  S d S r   )r.   rM   r6   	get_value)r   contextr   r   r   get_defining_qualified_valueL  s   
z)CompiledName.get_defining_qualified_valuec                 C   s8   z| j j}W n ty   d }Y nw d| jj|| jf S )Nz<%s: (%s).%s>)r.   rc   r4   r0   r!   r   r   r   r   r   rk   S  s   zCompiledName.__repr__c                 C   s   | j rdS |  jS )Nr%   )r   r   rn   r<   r   r   r   rn   Z  s   
zCompiledName.api_typec                 C   s   t |  gS r   )r   r   r<   r   r   r   inferc     zCompiledName.inferc                 C   s   t | j| j| jS r   )create_from_namer   r   r   r<   r   r   r   r   f  r=   z!CompiledName.infer_compiled_valueN)r!   r(   r)   r   rS   r   r   rk   r   rn   r   r   r   r   r   r   r   r   ;  s    
r   c                   @   s8   e Zd Zdd Zedd Zdd Zdd Zd	d
 ZdS )r^   c                 C   s   |j | _ || _d S r   )r.   _signature_param)r   compiled_valuerf   r   r   r   r   l     
zSignatureParamName.__init__c                 C   s   | j jS r   )r   rc   r<   r   r   r   r   p  s   zSignatureParamName.string_namec                 C   sB   |   | j }| jjr|d| jj 7 }| jjr|d| jj 7 }|S )Nz: rU   )Z_kind_stringr   r   has_annotationZannotation_stringhas_defaultZdefault_string)r   sr   r   r   	to_stringt  s   zSignatureParamName.to_stringc                 C   s   t t| jjS r   )getattrr   r   Z	kind_namer<   r   r   r   get_kind|  r   zSignatureParamName.get_kindc                 C   sL   | j }| jj}t}|jrtt||jg}|jr$t||j	}||
 O }|S r   )r   r.   r-   r   r   r   r2   re   r   
annotationZexecute_with_values)r   rb   r-   valuesr   r   r   r   r     s   zSignatureParamName.inferN)	r!   r(   r)   r   r   r   r   r   r   r   r   r   r   r^   k  s    
r^   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
r]   c                 C   s   |j | _ || _|| _d S r   )r.   r   _default)r   r   rc   re   r   r   r   r     s   
zUnresolvableParamName.__init__c                 C   s   t jS r   )r   POSITIONAL_ONLYr<   r   r   r   r     s   zUnresolvableParamName.get_kindc                 C   s   | j }| jr|d| j 7 }|S )NrU   )r   r   )r   stringr   r   r   r     s   zUnresolvableParamName.to_stringc                 C   r   r   r   r<   r   r   r   r     rP   zUnresolvableParamName.inferN)r!   r(   r)   r   r   r   r   r   r   r   r   r]     s
    r]   c                   @   s   e Zd Zdd ZdS )r~   c                 C   s   || _ || _|j| _d S r   )r   _valuer.   )r   valuerc   r   r   r   r     s   zCompiledValueName.__init__N)r!   r(   r)   r   r   r   r   r   r~     s    r~   c                   @   s    e Zd ZdZdd Zdd ZdS )EmptyCompiledNamez
    Accessing some names will raise an exception. To avoid not having any
    completions, just give Jedi the option to return this object. It infers to
    nothing.
    c                 C   s   |j | _|| _d S r   )r   r.   r   )r   r-   rc   r   r   r   r     r   zEmptyCompiledName.__init__c                 C   r   r   r   r<   r   r   r   r     rP   zEmptyCompiledName.inferN)r!   r(   r)   r*   r   r   r   r   r   r   r     s    r   c                   @   sT   e Zd ZdddZdd ZdddZedddd	d
Zdd Zdd Z	dd Z
dS )rq   Fc                 C   s   || _ || _|| _d S r   )r   r   rR   )r   r-   r   rR   r   r   r   r     s   
zCompiledValueFilter.__init__c                    s6   | j j | jj | j| fdd fddddS )Nc                    s    j | dS rr   )Zis_allowed_getattrrc   r#   rs   r   r   <lambda>  s    z)CompiledValueFilter.get.<locals>.<lambda>c                    s   |    v S r   )dirr   )r#   r   r   r     s    T)check_has_attribute)r   r#   r   rx   _getr   r   r   r   get  s   

zCompiledValueFilter.getc           	         s   | \}}}|durt | j| }|r fdd|D S |r$|s$g S |s(|s4| jjs4| j ddgS | jr=| s=g S | j |dgS )zU
        To remove quite a few access calls we introduced the callback here.
        Nc                    s   g | ]}t | qS r   )r~   r   r   r   r   r     s    z,CompiledValueFilter._get.<locals>.<listcomp>T)is_emptyr   )r2   r   r3   rx   _get_cached_namerR   )	r   rc   Zallowed_getattr_callbackZin_dir_callbackr   Zhas_attributer   Zproperty_return_annotationr   r   r   r   r     s*   
zCompiledValueFilter._getr   c                C   s   |rt | j|S | j||dS )Nr   )r   r   _create_name)r   rc   r   r   r   r   r   r     s   z$CompiledValueFilter._get_cached_namec              	      s|   ddl m} g }| jj \}  D ]}|| | fdd fdd7 }q| js<|r<|| jd D ]}||	 7 }q3|S )Nr   r   c                    s    |  S r   r   r   Z	dir_infosr   r   r         z,CompiledValueFilter.values.<locals>.<lambda>c                    s   |  v S r   r   r   r   r   r   r     r   type)
r   r   r   r#   Zget_dir_infosr   rR   r   rp   r   )r   r   namesZneeds_type_completionsrc   filterr   r   r   r     s   


zCompiledValueFilter.valuesc                 C   s   t | j| j||S r   )r   r   r   )r   rc   r   r   r   r   r     s   z CompiledValueFilter._create_namec                 C   s   d| j j| jf S ri   )r0   r!   r   r<   r   r   r   rk     r   zCompiledValueFilter.__repr__N)F)r!   r(   r)   r   r   r   r   r   r   r   rk   r   r   r   r   rq     s    


rq   floatstrintdict)zfloating point number	characterinteger
dictionaryr   c              	   C   sJ  z9d}|  d}t| |d D ]\}}|dkr|d7 }n|dkr%|d8 }|dkr/|| } nq| |d | }W n ttfyM   td d}d}Y nw dd	 }	 td||\}}|dkranqS|dd}t	d| ||d  }	|	du r~d}
||
fS ||	
  }td}|| |d }tdd|}t||}
||
fS )z
    Takes a function and returns the params and return value as a tuple.
    This is nothing more than a docstring parser.

    TODO docstrings like utime(path, (atime, mtime)) and a(b [, b]) -> None
    TODO docstrings like 'tuple of integers'
    r   (Nr   )zno brackets found - no paramrl   c                 S   sH   |  dd}t|D ]\}}|rd|vr||  d7  < qd|S )Nr   rT   rU   z=None)grouprX   	enumeratejoin)mr   iar   r   r   change_options,  s   
z+_parse_function_doc.<locals>.change_optionsTz ?\[([^\[\]]+)\]-rd   z-[>-]*    z(,\n|[^\n-])+z[nN]ew (.*)z\1())ry   r   rV   UnboundLocalErrorr   Zdbgresubnreplacesearchendcompilematchr   r[   subdocstr_defaultsr   )rm   countstartr   r   r   Z	param_strr   changesrr`   ry   patternZret_strr   r   r   rW     sJ   	



rW   c                 C   s@   |j j|d d}d }|D ]}t| ||d u rd n| d}q|S )N)re   r.   )r#   r$   create_cached_compiled_valuer   )r-   r   rc   Zaccess_pathsr   access_pathr   r   r   r   K  s   r   c                    s   d fdd	}|S )z5The cache doesn't care about keyword vs. normal args.Nc                    s    | ||S r   r   )r-   objr.   r    r   r   wrapperZ  r   z'_normalize_create_args.<locals>.wrapperr   r   )r    r   r   r   r   _normalize_create_argsX  s   r  c                 C   s6   d }|j D ]\}}t| ||d u rd n| d}q|S )Nr   )Zaccessesr   r   )r-   r   r   rc   rB   r   r   r   r2   _  s   r2   c                 C   s,   t |trJ |d u rt}nt}|| ||S r   )
isinstancer+   r   )r-   r#   r.   clsr   r   r   r   j  s
   r   )6r*   r   	functoolsr   inspectr   pathlibr   typingr   Zjedir   Zjedi.inference.utilsr   Z
jedi.cacher   Zjedi.inference.filtersr	   Zjedi.inference.namesr
   r   r   Zjedi.inference.base_valuer   r   r   Zjedi.inference.lazy_valuer   Zjedi.inference.compiled.accessr   Zjedi.inference.cacher   Zjedi.inference.helpersr   Zjedi.inference.signaturer   Zjedi.inference.contextr   r   r   r+   r   r   r^   r]   r~   r   rq   r   rW   r   r  r2   r   r   r   r   r   <module>   sR     v0 T	<