o
    Zh+G                     @   s2  d 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 ddlmZ e ZG dd deZG dd dZG dd deZ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ZG dd dZ d d! Z!G d"d# d#Z"e"g Z#d$d% Z$dS )'a4  
Values are the "values" that Python would return. However Values are at the
same time also the "values" that a user is currently sitting in.

A ValueSet is typically used to specify the return of a function or any other
static analysis operation. In jedi there are always multiple returns and not
just one.
    )reduce)add)zip_longest)Name)debug)clean_scope_docstringSimpleGetItemNotFound)safe_property)%inference_state_as_method_param_cache)memoize_methodc                   @   s   e Zd ZdS )HasNoContextN)__name__
__module____qualname__ r   r   P/var/www/html/lang_env/lib/python3.10/site-packages/jedi/inference/base_value.pyr      s    r   c                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zd"ddZdd Z	d#ddZ
		d$ddZdd Zdd Zd"ddZdd Zdd Zed d! ZdS )%HelperValueMixinc                 C   s.   | }|j d u r| S 	 |j d u r|S |j }qN)parent_context
as_context)selfvaluer   r   r   get_root_context   s   

z!HelperValueMixin.get_root_contextc                 C   s   | j j| |dS )N	argumentsinference_stateexecuter   r   r   r   r   r   (      zHelperValueMixin.executec                 G   s,   ddl m} |dd |D }| j| |S )Nr   )ValuesArgumentsc                 S   s   g | ]}t |gqS r   ValueSet.0r   r   r   r   
<listcomp>-   s    z8HelperValueMixin.execute_with_values.<locals>.<listcomp>)Zjedi.inference.argumentsr!   r   r   )r   Z
value_listr!   r   r   r   r   execute_with_values+   s   z$HelperValueMixin.execute_with_valuesc                 C   s   |   S r   r'   r   r   r   r   execute_annotation0      z#HelperValueMixin.execute_annotationc                 C   s
   t | gS r   r"   r)   r   r   r   gather_annotation_classes3      
z*HelperValueMixin.gather_annotation_classesNFc                 C   s   t dd | ||D S )Nc                 s       | ]}|  V  qd S r   inferr%   Z
lazy_valuer   r   r   	<genexpr>7   
    
z:HelperValueMixin.merge_types_of_iterate.<locals>.<genexpr>r#   	from_setsiterate)r   contextualized_nodeis_asyncr   r   r   merge_types_of_iterate6   s   

z'HelperValueMixin.merge_types_of_iteratec                 c   sd    t |tr|nd }| j|dE d H  |  r.ddlm} |t| hD ]}| E d H  q$d S d S )N)origin_scoper   )convert_values)
isinstancer   Zget_filtersis_stubZ!jedi.inference.gradual.conversionr;   r#   )r   name_or_strr:   r;   cr   r   r   _get_value_filters<   s   z#HelperValueMixin._get_value_filtersTc                 C   s6   ddl m} | |}|||}td|| | |S )Nr   )finderzcontext.goto %s in (%s): %s)jedi.inferencerA   r@   Zfilter_namer   dbg)r   r>   name_contextanalysis_errorsrA   filtersnamesr   r   r   gotoE   s
   
zHelperValueMixin.gotoc           	      C   s   |du r| }|  |||}tdd |D }|s(t|tr!|jn|}| |}|s@|s@|r@t|tr@ddlm} |	|| | t
d|| |S )zZ
        :param position: Position of the last statement -> tuple of line, column
        Nc                 s   r.   r   r/   )r%   namer   r   r   r2   T       z6HelperValueMixin.py__getattribute__.<locals>.<genexpr>r   analysisz context.names_to_types: %s -> %s)rH   r#   r5   r<   r   r   py__getattribute__alternativesrB   rL   Zadd_attribute_errorr   rC   )	r   r>   rD   positionrE   rG   valuesnrL   r   r   r   py__getattribute__L   s   

z#HelperValueMixin.py__getattribute__c                 C   s"   |  d}|std|  | S )N	__await__z"Tried to run __await__ on value %s)rQ   r   warningr'   )r   Zawait_value_setr   r   r   py__await__a   s   
zHelperValueMixin.py__await__c                 C   s   | j jS r   )rI   string_namer)   r   r   r   
py__name__g   r+   zHelperValueMixin.py__name__c                 C   sV   t d|  |r&ddlm} t|| d d d  gS | |S )Nz
iterate %sr   )LazyKnownValues	__aiter__	__anext__rR   )	r   rC   jedi.inference.lazy_valuerW   iterrQ   r'   py__stop_iteration_returns
py__iter__)r   r7   r8   rW   r   r   r   r6   j   s   


zHelperValueMixin.iteratec                 C   s   t jd| |f dd- |  D ]}||r't jddd  W d    dS qt jddd 	 W d    dS 1 s;w   Y  d S )Nzsubclass matching of %s <=> %sZBLUE)colorzmatched subclass TrueTzmatched subclass FalseF)r   increase_indent_cmZ	py__mro__is_same_classrC   )r   class_valueclsr   r   r   is_sub_class_ofz   s   
$z HelperValueMixin.is_sub_class_ofc                 C   s"   t |jtjkr|| S | |kS r   )typer`   r   )r   Zclass2r   r   r   r`      s   
zHelperValueMixin.is_same_classc                 O   s   | j |i |S r   )_as_contextr   argskwargsr   r   r   r      s   zHelperValueMixin.as_contextNF)NT)NNT)r   r   r   r   r   r'   r*   r,   r9   r@   rH   rQ   rT   rV   r6   rc   r`   r   r   r   r   r   r   r      s&    


	


r   c                   @   s  e Zd ZdZdZdZdZdAddZdd Zdd	 Z	dAd
dZ
dAd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d d! Zd"d# Zd$d% Zefd&d'Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Z d6d7 Z!d8d9 Z"e#d:d; Z$dBd=d>Z%d?d@ Z&dS )CValuez*
    To be implemented by subclasses.
    NZnot_defined_please_report_bugc                 C      || _ || _d S r   )r   r   )r   r   r   r   r   r   __init__      
zValue.__init__c                 C   s*   ddl m} |j|jd|jd|  d tS )Nr   rK   ztype-error-not-subscriptablez+TypeError: '%s' object is not subscriptablemessage)rB   rL   r   contextnode	NO_VALUES)r   Zindex_value_setr7   rL   r   r   r   py__getitem__   s   zValue.py__getitem__c                 C      t r   r   )r   indexr   r   r   py__simple_getitem__      zValue.py__simple_getitem__c                 C   s6   |d urddl m} |j|jd|jd|  d tg S )Nr   rK   ztype-error-not-iterablez&TypeError: '%s' object is not iterablern   )rB   rL   r   rp   rq   r[   )r   r7   rL   r   r   r   r]      s   zValue.py__iter__c                 C   s
   |  |S r   )r]   )r   r7   r   r   r   
py__next__   r-   zValue.py__next__c                 C   s   g S r   r   r)   r   r   r   get_signatures   rw   zValue.get_signaturesc                 C      dS ri   r   r)   r   r   r   is_class   rw   zValue.is_classc                 C   rz   ri   r   r)   r   r   r   is_class_mixin   rw   zValue.is_class_mixinc                 C   rz   ri   r   r)   r   r   r   is_instance   rw   zValue.is_instancec                 C   rz   ri   r   r)   r   r   r   is_function   rw   zValue.is_functionc                 C   rz   ri   r   r)   r   r   r   	is_module   rw   zValue.is_modulec                 C   rz   ri   r   r)   r   r   r   is_namespace   rw   zValue.is_namespacec                 C   rz   ri   r   r)   r   r   r   is_compiled   rw   zValue.is_compiledc                 C   rz   ri   r   r)   r   r   r   is_bound_method   rw   zValue.is_bound_methodc                 C   rz   ri   r   r)   r   r   r   is_builtins_module   rw   zValue.is_builtins_modulec                 C   rz   )z
        Since Wrapper is a super class for classes, functions and modules,
        the return value will always be true.
        Tr   r)   r   r   r   
py__bool__   s   zValue.py__bool__c                 C   s,   z| j j W n
 ty   Y dS w t| j S )N )	tree_nodeZget_doc_nodeAttributeErrorr   r)   r   r   r   	py__doc__   s   
zValue.py__doc__c                 C   s   |t u r
td|  |S )Nz'There exists no safe value for value %s)sentinel
ValueError)r   defaultr   r   r   get_safe_value   s   zValue.get_safe_valuec                 C   s   t d|| | tS )Nz!%s not possible between %s and %sr   rS   rr   )r   otheroperatorr   r   r   execute_operation   s   zValue.execute_operationc                 C      t d|  tS )Nzno execution possible %sr   r   r   r   r   
py__call__      zValue.py__call__c                 C   r   )Nz0Not possible to return the stop iterations of %sr   r)   r   r   r   r\      r   z Value.py__stop_iteration_returnsc                 C      t S )zH
        For now a way to add values in cases like __getattr__.
        )rr   )r   r>   r   r   r   rM      s   z$Value.py__getattribute__alternativesc                 C   s   t d|  t| gS )NzNo __get__ defined on %s)r   rS   r#   )r   instancera   r   r   r   	py__get__   s   
zValue.py__get__c                 C   r   r   )NotImplemented)r   Zcalling_instancer   ra   r   r   r   py__get__on_class   rw   zValue.py__get__on_classc                 C      d S r   r   r)   r   r   r   get_qualified_names     zValue.get_qualified_namesc                 C   
   | j  S r   )r   r=   r)   r   r   r   r=     s   
zValue.is_stubc                 C   rt   r   )r   r)   r   r   r   re     rw   zValue._as_contextc                 C   rt   r   NotImplementedErrorr)   r   r   r   rI     r   z
Value.nameTc                 C   r   r   r   )r   add_class_infor   r   r   get_type_hint  rw   zValue.get_type_hintc                 C   s   i S )an  
        When the current instance represents a type annotation, this method
        tries to find information about undefined type vars and returns a dict
        from type var name to value set.

        This is for example important to understand what `iter([1])` returns.
        According to typeshed, `iter` returns an `Iterator[_T]`:

            def iter(iterable: Iterable[_T]) -> Iterator[_T]: ...

        This functions would generate `int` for `_T` in this case, because it
        unpacks the `Iterable`.

        Parameters
        ----------

        `self`: represents the annotation of the current parameter to infer the
            value for. In the above example, this would initially be the
            `Iterable[_T]` of the `iterable` parameter and then, when recursing,
            just the `_T` generic parameter.

        `value_set`: represents the actual argument passed to the parameter
            we're inferred for, or (for recursive calls) their types. In the
            above example this would first be the representation of the list
            `[1]` and then, when recursing, just of `1`.
        r   )r   	value_setr   r   r   infer_type_vars  s   zValue.infer_type_varsr   T)'r   r   r   __doc__r   Z
array_typeZapi_typerl   rs   rv   r]   rx   ry   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r\   rM   r   r   r   r=   re   propertyrI   r   r   r   r   r   r   rj      sH    





rj   NFc                 C   s   t dd | j||dD S )z
    Calls `iterate`, on all values but ignores the ordering and just returns
    all values that the iterate functions yield.
    c                 s   r.   r   r/   r1   r   r   r   r2   8  r3   z!iterate_values.<locals>.<genexpr>r8   r4   )rO   r7   r8   r   r   r   iterate_values3  s   
r   c                   @   s2   e Zd Zedd Zee dd Zdd ZdS )_ValueWrapperBasec                 C   sB   ddl m} | jj}|jd ur|| |jS ddlm} || |jS )Nr   )	ValueName)CompiledValueName)Zjedi.inference.namesr   _wrapped_valuerI   Z	tree_nameZjedi.inference.compiledr   rU   )r   r   Zwrapped_namer   r   r   r   rI   ?  s   
z_ValueWrapperBase.namec                 O   s   | |i |S r   r   )rb   r   rg   rh   r   r   r   create_cachedI  s   z_ValueWrapperBase.create_cachedc                 C   s   |dksJ dt | j|S )Nr   zProblem with _get_wrapped_value)getattrr   )r   rI   r   r   r   __getattr__N  s   z_ValueWrapperBase.__getattr__N)	r   r   r   r
   rI   classmethodr   r   r   r   r   r   r   r   >  s    
	r   c                   @   s,   e Zd Zeedd Zdd Zdd ZdS )LazyValueWrapperc                 C   s6   t d |  W  d    S 1 sw   Y  d S )NzResolve lazy value wrapper)r   r_   _get_wrapped_valuer)   r   r   r   r   T  s   $zLazyValueWrapper._wrapped_valuec                 C   s   d| j j S )Nz<%s>)	__class__r   r)   r   r   r   __repr__Z     zLazyValueWrapper.__repr__c                 C   rt   r   r   r)   r   r   r   r   ]  rw   z#LazyValueWrapper._get_wrapped_valueN)r   r   r   r
   r   r   r   r   r   r   r   r   r   S  s    r   c                   @   s   e Zd Zdd Zdd ZdS )ValueWrapperc                 C   s
   || _ d S r   )r   )r   Zwrapped_valuer   r   r   rl   b  r-   zValueWrapper.__init__c                 C      d| j j| jf S )Nz%s(%s))r   r   r   r)   r   r   r   r   e     zValueWrapper.__repr__N)r   r   r   rl   r   r   r   r   r   r   a  s    r   c                       s$   e Zd Z fddZdd Z  ZS )	TreeValuec                    s   t  || || _d S r   )superrl   r   )r   r   r   r   r   r   r   rl   j  s   
zTreeValue.__init__c                 C   r   )Nz<%s: %s>)r   r   r   r)   r   r   r   r   n  r   zTreeValue.__repr__)r   r   r   rl   r   __classcell__r   r   r   r   r   i  s    r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
ContextualizedNodec                 C   rk   r   )rp   rq   )r   rp   rq   r   r   r   rl   s  rm   zContextualizedNode.__init__c                 C   r   r   )rp   r   r)   r   r   r   r   w  r-   z#ContextualizedNode.get_root_contextc                 C   s   | j | jS r   )rp   Z
infer_noderq   r)   r   r   r   r0   z  s   zContextualizedNode.inferc                 C   s   d| j j| j| jf S )Nz<%s: %s in %s>)r   r   rq   rp   r)   r   r   r   r   }     zContextualizedNode.__repr__N)r   r   r   rl   r   r0   r   r   r   r   r   r   r  s
    r   c              	   C   s   t }t }|D ]+}|jd d}t|tttttfv r-z	|| 	|O }W q t
y,   Y nw || q|s7|sA|| t||O }td| |S )N)r   zpy__getitem__ result: %s)rr   setr   rd   floatintstrslicebytesrv   r	   r   rs   r#   r   rC   )r   Zindex_valuesr7   resultZunused_valuesZindex_valueru   r   r   r   _getitem  s&   r   c                   @   s   e Zd Z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dd Zdd Zdd Zd8d!d"Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd9d4d5Zd6d7 ZdS ):r#   c                 C   s&   t || _|D ]	}t|trJ qd S r   )	frozenset_setr<   r#   )r   iterabler   r   r   r   rl     s   
zValueSet.__init__c                 C   s   |  | }||_|S r   )__new__r   )rb   Z
frozenset_r   r   r   r   _from_frozen_set  s   
zValueSet._from_frozen_setc                 C   s@   t  }|D ]}t|tr||jO }q|t|O }q| t|S )z7
        Used to work with an iterable of set.
        )r   r<   r#   r   r   r   )rb   ZsetsZ
aggregatedset_r   r   r   r5     s   
zValueSet.from_setsc                 C   s   |  | j|jB S r   r   r   r   r   r   r   r   __or__  r   zValueSet.__or__c                 C   s   |  | j|j@ S r   r   r   r   r   r   __and__  r   zValueSet.__and__c                 C   
   t | jS r   )r[   r   r)   r   r   r   __iter__  r-   zValueSet.__iter__c                 C   r   r   )boolr   r)   r   r   r   __bool__  r-   zValueSet.__bool__c                 C   r   r   )lenr   r)   r   r   r   __len__  r-   zValueSet.__len__c                 C   s   dd dd | jD  S )NzS{%s}, c                 s   s    | ]}t |V  qd S r   )r   )r%   sr   r   r   r2     rJ   z$ValueSet.__repr__.<locals>.<genexpr>)joinr   r)   r   r   r   r        zValueSet.__repr__c                 C   s   |  t|| jS r   )r   filterr   )r   Zfilter_funcr   r   r   r     r   zValueSet.filterc                    s    fdd}|S )Nc                     s     fddjD S )Nc                 3   s$    | ]}t | i V  qd S r   )r   r$   )rg   rh   rI   r   r   r2     s
    
z7ValueSet.__getattr__.<locals>.mapper.<locals>.<genexpr>)r5   r   rg   rh   rI   r   r   r   mapper  s   z$ValueSet.__getattr__.<locals>.mapperr   )r   rI   r   r   r   r   r     s   zValueSet.__getattr__c                 C   s   | j |j kS r   r   r   r   r   r   __eq__  r   zValueSet.__eq__c                 C   s   |  | S r   )r   r   r   r   r   __ne__  r   zValueSet.__ne__c                 C   r   r   )hashr   r)   r   r   r   __hash__  r-   zValueSet.__hash__c                 C   s   t dd | jD S )Nc                 s   r.   r   )py__class__r%   r?   r   r   r   r2     rJ   z'ValueSet.py__class__.<locals>.<genexpr>)r#   r   r)   r   r   r   r     s   zValueSet.py__class__NFc                 #   sJ    ddl m}  fdd| jD }t| D ]}|dd |D V  qd S )Nr   )get_merged_lazy_valuec                    s   g | ]	}|j  d qS )r   )r6   r   r7   r8   r   r   r&     s    z$ValueSet.iterate.<locals>.<listcomp>c                 S   s   g | ]}|d ur|qS r   r   )r%   lr   r   r   r&         )rZ   r   r   r   )r   r7   r8   r   Z
type_itersZlazy_valuesr   r   r   r6     s   zValueSet.iteratec                    s   t  fdd| jD S )Nc                 3   s    | ]
}|j | V  qd S r   r   r   r   r   r   r2     s    z#ValueSet.execute.<locals>.<genexpr>r#   r5   r   r   r   r   r   r     r   zValueSet.executec                       t  fdd| jD S )Nc                 3        | ]}|j  i V  qd S r   r(   r   r   r   r   r2         z/ValueSet.execute_with_values.<locals>.<genexpr>r   rf   r   r   r   r'        zValueSet.execute_with_valuesc                    s   t t fdd| jD g S )Nc                    s   g | ]
}|j  i qS r   )rH   r   r   r   r   r&     s    z!ValueSet.goto.<locals>.<listcomp>)r   r   r   rf   r   r   r   rH     s   zValueSet.gotoc                    r   )Nc                 3   r   r   )rQ   r   r   r   r   r2     r   z.ValueSet.py__getattribute__.<locals>.<genexpr>r   rf   r   r   r   rQ     r   zValueSet.py__getattribute__c                    r   )Nc                 3   s&    | ]}t |g R i V  qd S r   )r   r   r   r   r   r2     s   $ z$ValueSet.get_item.<locals>.<genexpr>r   rf   r   r   r   get_item  r   zValueSet.get_itemc              	   C   sF   |  g }| jD ]}zt||}W n	 ty   Y qw || O }q|S r   )r   r   r   r   )r   Zfunction_namer   r?   methodr   r   r   	try_merge  s   

zValueSet.try_mergec                 C   s   t dd | jD S )Nc                 S   s   g | ]}|  qS r   )r,   r   r   r   r   r&     s    z6ValueSet.gather_annotation_classes.<locals>.<listcomp>r   r)   r   r   r   r,      r   z"ValueSet.gather_annotation_classesc                 C   s   dd | j D S )Nc                 S   s   g | ]}|  D ]}|qqS r   )ry   )r%   r?   sigr   r   r   r&     s    z+ValueSet.get_signatures.<locals>.<listcomp>r   r)   r   r   r   ry     r    zValueSet.get_signaturesTc                    s    fdd| j D }ttd |}t|dkr|d S d|v }|r&|d t|dkr.d S t|dkr9|d }ndd| }|rFd| }|S )	Nc                    s   g | ]}|j  d qS )r   )r   )r%   vr   r   r   r&     r   z*ValueSet.get_type_hint.<locals>.<listcomp>   r   Nonez	Union[%s]r   zOptional[%s])r   sortedr   r   remover   )r   r   tZ
type_hintsoptionalr   r   r   r   r     s   

zValueSet.get_type_hintc                 C   s0   ddl m} i }| jD ]
}|||| q|S )Nr   )merge_type_var_dicts)Z!jedi.inference.gradual.annotationr   r   r   )r   r   r   Ztype_var_dictr   r   r   r   r     s   
zValueSet.infer_type_varsri   r   )r   r   r   rl   r   r   r5   r   r   r   r   r   r   r   r   r   r   r   r   r6   r   r'   rH   rQ   r   r   r,   ry   r   r   r   r   r   r   r#     s:    



r#   c                    s    fdd}|S )Nc                     s   t  | i |S r   r"   r   funcr   r   wrapper+  r   z&iterator_to_value_set.<locals>.wrapperr   )r   r   r   r   r   iterator_to_value_set*  s   r   ri   )%r   	functoolsr   r   r   	itertoolsr   Zparso.python.treer   Zjedir   Zjedi.parser_utilsr   Zjedi.inference.helpersr	   Zjedi.inference.utilsr
   Zjedi.inference.cacher   Z
jedi.cacher   objectr   	Exceptionr   r   rj   r   r   r   r   r   r   r   r#   rr   r   r   r   r   r   <module>   s6    r 
%	 