a
    lc-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   U/var/www/html/django/DPS/env/lib/python3.9/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   s0   | }|j d u r| S |j d u r$|S |j }qd S 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   (   s    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>-       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   s    z#HelperValueMixin.execute_annotationc                 C   s
   t | gS r   r!   r)   r   r   r   gather_annotation_classes3   s    z*HelperValueMixin.gather_annotation_classesNFc                 C   s   t dd | ||D S )Nc                 s   s   | ]}|  V  qd S r   inferr$   Z
lazy_valuer   r   r   	<genexpr>7   s   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   s^   t |tr|nd }| j|dE d H  |  rZddlm} |t| hD ]}| E d H  qFd S )N)origin_scoper   )convert_values)
isinstancer   Zget_filtersis_stubZ!jedi.inference.gradual.conversionr7   r"   )r   name_or_strr6   r7   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.inferencer=   r<   Zfilter_namer   dbg)r   r:   name_contextanalysis_errorsr=   filtersnamesr   r   r   gotoE   s
    
zHelperValueMixin.gotoc           	      C   s   |du r| }|  |||}tdd |D }|sPt|trB|jn|}| |}|s|s|rt|trddlm} |	|| | t
d|| |S )zZ
        :param position: Position of the last statement -> tuple of line, column
        Nc                 s   s   | ]}|  V  qd S r   r,   )r$   namer   r   r   r/   T   r&   z6HelperValueMixin.py__getattribute__.<locals>.<genexpr>r   analysisz context.names_to_types: %s -> %s)rD   r"   r1   r8   r   r   py__getattribute__alternativesr>   rG   Zadd_attribute_errorr   r?   )	r   r:   r@   positionrA   rC   valuesnrG   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)rL   r   warningr'   )r   Zawait_value_setr   r   r   py__await__a   s    
zHelperValueMixin.py__await__c                 C   s   | j jS r   )rE   string_namer)   r   r   r   
py__name__g   s    zHelperValueMixin.py__name__c                 C   sV   t d|  |rLddlm} t|| d d d  gS | |S )Nz
iterate %sr   )LazyKnownValues	__aiter__	__anext__rM   )	r   r?   jedi.inference.lazy_valuerR   iterrL   r'   py__stop_iteration_returns
py__iter__)r   r3   r4   rR   r   r   r   r2   j   s    
zHelperValueMixin.iteratec                 C   s   t jd| |f ddX |  D ].}||r t jddd  W d    dS q t jddd W d    dS 1 st0    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_classr?   )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)NF)r   r   r   r   r   r'   r*   r+   r5   r<   rD   rL   rO   rQ   r2   r^   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	dBd
dZ
dCd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$dDd=d>Z%d?d@ Z&dS )EValuez*
    To be implemented by subclasses.
    NZnot_defined_please_report_bugc                 C   s   || _ || _d S r   )r   r   )r   r   r   r   r   r   __init__   s    zValue.__init__c                 C   s*   ddl m} |j|jd|jd|  d tS )Nr   rF   ztype-error-not-subscriptablez+TypeError: '%s' object is not subscriptablemessage)r>   rG   r   contextnode	NO_VALUES)r   Zindex_value_setr3   rG   r   r   r   py__getitem__   s    zValue.py__getitem__c                 C   s   t d S r   r   )r   indexr   r   r   py__simple_getitem__   s    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   rF   ztype-error-not-iterablez&TypeError: '%s' object is not iterablerf   )r>   rG   r   rh   ri   rV   )r   r3   rG   r   r   r   rX      s    zValue.py__iter__c                 C   s
   |  |S r   )rX   )r   r3   r   r   r   
py__next__   s    zValue.py__next__c                 C   s   g S r   r   r)   r   r   r   get_signatures   s    zValue.get_signaturesc                 C   s   dS NFr   r)   r   r   r   is_class   s    zValue.is_classc                 C   s   dS rp   r   r)   r   r   r   is_class_mixin   s    zValue.is_class_mixinc                 C   s   dS rp   r   r)   r   r   r   is_instance   s    zValue.is_instancec                 C   s   dS rp   r   r)   r   r   r   is_function   s    zValue.is_functionc                 C   s   dS rp   r   r)   r   r   r   	is_module   s    zValue.is_modulec                 C   s   dS rp   r   r)   r   r   r   is_namespace   s    zValue.is_namespacec                 C   s   dS rp   r   r)   r   r   r   is_compiled   s    zValue.is_compiledc                 C   s   dS rp   r   r)   r   r   r   is_bound_method   s    zValue.is_bound_methodc                 C   s   dS rp   r   r)   r   r   r   is_builtins_module   s    zValue.is_builtins_modulec                 C   s   dS )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   s0   z| j j W n ty    Y dS 0 t| j S d 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   rN   rj   )r   otheroperatorr   r   r   execute_operation   s    zValue.execute_operationc                 C   s   t d|  tS )Nzno execution possible %sr   r   r   r   r   
py__call__   s    zValue.py__call__c                 C   s   t d|  tS )Nz0Not possible to return the stop iterations of %sr   r)   r   r   r   rW      s    z Value.py__stop_iteration_returnsc                 C   s   t S )zH
        For now a way to add values in cases like __getattr__.
        )rj   )r   r:   r   r   r   rH      s    z$Value.py__getattribute__alternativesc                 C   s   t d|  t| gS )NzNo __get__ defined on %s)r   rN   r"   )r   instancer\   r   r   r   	py__get__   s    zValue.py__get__c                 C   s   t S r   )NotImplemented)r   Zcalling_instancer   r\   r   r   r   py__get__on_class   s    zValue.py__get__on_classc                 C   s   d S r   r   r)   r   r   r   get_qualified_names  s    zValue.get_qualified_namesc                 C   s
   | j  S r   )r   r9   r)   r   r   r   r9     s    zValue.is_stubc                 C   s   t d S r   )r   r)   r   r   r   r`     s    zValue._as_contextc                 C   s   t d S r   NotImplementedErrorr)   r   r   r   rE     s    z
Value.nameTc                 C   s   d S r   r   )r   add_class_infor   r   r   get_type_hint  s    zValue.get_type_hintc                 C   s   i S )ap  
        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 inferrined 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_vars)N)N)N)T)'r   r   r   __doc__r|   Z
array_typeZapi_typere   rk   rm   rX   rn   ro   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r~   r   r   r   r   rW   rH   r   r   r   r9   r`   propertyrE   r   r   r   r   r   r   rd      sF   





rd   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   s   | ]}|  V  qd S r   r,   r.   r   r   r   r/   8  s   z!iterate_values.<locals>.<genexpr>r4   r0   )rJ   r3   r4   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   sF   ddl m} | jj}|jd ur*|| |jS ddlm} || |jS d S )Nr   )	ValueName)CompiledValueName)Zjedi.inference.namesr   _wrapped_valuerE   Z	tree_nameZjedi.inference.compiledr   rP   )r   r   Zwrapped_namer   r   r   r   rE   ?  s    
z_ValueWrapperBase.namec                 O   s   | |i |S r   r   )r]   r   rb   rc   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   rE   r   r   r   __getattr__N  s    z_ValueWrapperBase.__getattr__N)	r   r   r   r
   rE   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(0    Y  d S )NzResolve lazy value wrapper)r   rZ   _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  s    zLazyValueWrapper.__repr__c                 C   s   t d S r   r   r)   r   r   r   r   ]  s    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   re   b  s    zValueWrapper.__init__c                 C   s   d| j j| jf S )Nz%s(%s))r   r   r   r)   r   r   r   r   e  s    zValueWrapper.__repr__N)r   r   r   re   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   )superre   r|   )r   r   r   r|   r   r   r   re   j  s    zTreeValue.__init__c                 C   s   d| j j| jf S )Nz<%s: %s>)r   r   r|   r)   r   r   r   r   n  s    zTreeValue.__repr__)r   r   r   re   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   s   || _ || _d S r   )rh   ri   )r   rh   ri   r   r   r   re   s  s    zContextualizedNode.__init__c                 C   s
   | j  S r   )rh   r   r)   r   r   r   r   w  s    z#ContextualizedNode.get_root_contextc                 C   s   | j | jS r   )rh   Z
infer_noderi   r)   r   r   r   r-   z  s    zContextualizedNode.inferc                 C   s   d| j j| j| jf S )Nz<%s: %s in %s>)r   r   ri   rh   r)   r   r   r   r   }  s    zContextualizedNode.__repr__N)r   r   r   re   r   r-   r   r   r   r   r   r   r  s   r   c              	   C   s   t }t }|D ]Z}|jd d}t|tttttfv r^z|| 	|O }W qW n t
y\   Y n0 || q|sr|s|| t||O }td| |S )N)r   zpy__getitem__ result: %s)rj   setr   r_   floatintstrslicebytesrm   r	   r   rk   r"   r   r?   )r   Zindex_valuesr3   resultZunused_valuesZindex_valuerl   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_setr8   r"   )r   iterabler   r   r   r   re     s    
zValueSet.__init__c                 C   s   |  | }||_|S r   )__new__r   )r]   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   r8   r"   r   r   r   )r]   ZsetsZ
aggregatedset_r   r   r   r1     s    
zValueSet.from_setsc                 C   s   |  | j|jB S r   r   r   r   r   r   r   r   __or__  s    zValueSet.__or__c                 C   s   |  | j|j@ S r   r   r   r   r   r   __and__  s    zValueSet.__and__c                 C   s
   t | jS r   )rV   r   r)   r   r   r   __iter__  s    zValueSet.__iter__c                 C   s
   t | jS r   )boolr   r)   r   r   r   __bool__  s    zValueSet.__bool__c                 C   s
   t | jS r   )lenr   r)   r   r   r   __len__  s    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   r/     r&   z$ValueSet.__repr__.<locals>.<genexpr>)joinr   r)   r   r   r   r     s    zValueSet.__repr__c                 C   s   |  t|| jS r   )r   filterr   )r   Zfilter_funcr   r   r   r     s    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#   )rb   rc   rE   r   r   r/     s   z7ValueSet.__getattr__.<locals>.mapper.<locals>.<genexpr>)r1   r   rb   rc   rE   r   r   r   mapper  s    z$ValueSet.__getattr__.<locals>.mapperr   )r   rE   r   r   r   r   r     s    zValueSet.__getattr__c                 C   s   | j |j kS r   r   r   r   r   r   __eq__  s    zValueSet.__eq__c                 C   s   |  | S r   )r   r   r   r   r   __ne__  s    zValueSet.__ne__c                 C   s
   t | jS r   )hashr   r)   r   r   r   __hash__  s    zValueSet.__hash__c                 C   s   t dd | jD S )Nc                 s   s   | ]}|  V  qd S r   )py__class__r$   r;   r   r   r   r/     r&   z'ValueSet.py__class__.<locals>.<genexpr>)r"   r   r)   r   r   r   r     s    zValueSet.py__class__NFc                 #   sH   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   )r2   r   r3   r4   r   r   r%     r&   z$ValueSet.iterate.<locals>.<listcomp>c                 S   s   g | ]}|d ur|qS r   r   )r$   lr   r   r   r%     r&   )rU   r   r   r   )r   r3   r4   r   Z
type_itersZlazy_valuesr   r   r   r2     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   r/     r&   z#ValueSet.execute.<locals>.<genexpr>r"   r1   r   r   r   r   r   r     s    zValueSet.executec                    s   t  fdd| jD S )Nc                 3   s   | ]}|j  i V  qd S r   r(   r   r   r   r   r/     r&   z/ValueSet.execute_with_values.<locals>.<genexpr>r   ra   r   r   r   r'     s    zValueSet.execute_with_valuesc                    s   t t fdd| jD g S )Nc                    s   g | ]}|j  i qS r   )rD   r   r   r   r   r%     r&   z!ValueSet.goto.<locals>.<listcomp>)r   r   r   ra   r   r   r   rD     s    zValueSet.gotoc                    s   t  fdd| jD S )Nc                 3   s   | ]}|j  i V  qd S r   )rL   r   r   r   r   r/     r&   z.ValueSet.py__getattribute__.<locals>.<genexpr>r   ra   r   r   r   rL     s    zValueSet.py__getattribute__c                    s   t  fdd| jD S )Nc                 3   s$   | ]}t |g R i V  qd S r   )r   r   r   r   r   r/     r&   z$ValueSet.get_item.<locals>.<genexpr>r   ra   r   r   r   get_item  s    zValueSet.get_itemc              	   C   sF   |  g }| jD ]0}zt||}W n ty4   Y q0 || 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%     r&   z6ValueSet.gather_annotation_classes.<locals>.<listcomp>r   r)   r   r   r   r+      s    z"ValueSet.gather_annotation_classesc                 C   s   dd | j D S )Nc                 S   s   g | ]}|  D ]}|qqS r   )ro   )r$   r;   sigr   r   r   r%     r&   z+ValueSet.get_signatures.<locals>.<listcomp>r   r)   r   r   r   ro     s    zValueSet.get_signaturesTc                    s    fdd| j D }ttd |}t|dkr6|d S d|v }|rL|d t|dkr\d S t|dkrr|d }ndd| }|rd| }|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_vars)NF)T)r   r   r   re   r   r   r1   r   r   r   r   r   r   r   r   r   r   r   r   r2   r   r'   rD   rL   r   r   r+   ro   r   r   r   r   r   r   r"     s8   



r"   c                    s    fdd}|S )Nc                     s   t  | i |S r   r!   r   funcr   r   wrapper+  s    z&iterator_to_value_set.<locals>.wrapperr   )r   r   r   r   r   iterator_to_value_set*  s    r   )NF)%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   rd   r   r   r   r   r   r   r   r"   rj   r   r   r   r   r   <module>   s4   r %
	 