
    f+G                     r   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e      Z G d d      Z G d de      Zd"dZ G d de      Z G d de      Z G d de      Z G d de      Z G d d      Z d Z! G d d       Z" e"g       Z#d! Z$y)#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                       e Zd Zy)HasNoContextN)__name__
__module____qualname__     T/var/www/cvtools/html/venv/lib/python3.12/site-packages/jedi/inference/base_value.pyr   r      s    r   r   c                   |    e Zd Zd Zd Zd Zd Zd ZddZd Z	dd	Z
	 	 dd
Zd Zd ZddZd Zd Zed        Zy)HelperValueMixinc                 v    | }|j                   |j                         S 	 |j                   |S |j                   }N)parent_context
as_context)selfvalues     r   get_root_contextz!HelperValueMixin.get_root_context   sF    '##%%##+((E r   c                 <    | j                   j                  | |      S )N)	argumentsinference_stateexecuter   r    s     r   r#   zHelperValueMixin.execute(   s    ##++DI+FFr   c                     ddl m}  ||D cg c]  }t        |g       c}      }| j                  j	                  | |      S c c}w )Nr   )ValuesArguments)jedi.inference.argumentsr&   ValueSetr"   r#   )r   
value_listr&   r   r    s        r   execute_with_valuesz$HelperValueMixin.execute_with_values+   s@    <#J$O5Xug%6$OP	##++D)<< %Ps   Ac                 "    | j                         S r   r*   r   s    r   execute_annotationz#HelperValueMixin.execute_annotation0   s    ''))r   c                     t        | g      S r   r(   r-   s    r   gather_annotation_classesz*HelperValueMixin.gather_annotation_classes3   s    r   Nc                 Z    t         j                  d | j                  ||      D              S )Nc              3   <   K   | ]  }|j                           y wr   infer.0
lazy_values     r   	<genexpr>z:HelperValueMixin.merge_types_of_iterate.<locals>.<genexpr>7   s!      "
 "
   r(   	from_setsiterate)r   contextualized_nodeis_asyncs      r   merge_types_of_iteratez'HelperValueMixin.merge_types_of_iterate6   s.    !! "
"ll+>I"
 
 	
r   c              #      K   t        |t              r|nd }| j                  |      E d {    | j                         r6ddlm}  |t        | h            D ]  }|j                         E d {     y y 7 K7 
w)N)origin_scoper   )convert_values)
isinstancer   get_filtersis_stub!jedi.inference.gradual.conversionrC   r(   )r   name_or_strrB   rC   cs        r   _get_value_filtersz#HelperValueMixin._get_value_filters<   ss     &0d&C{###>>><<>H#HdV$45 +==?**+  	?
 +s"   *A<A8AA</A:0	A<:A<c                     ddl m} | j                  |      }|j                  ||      }t	        j
                  d|| |       |S )Nr   )finderzcontext.goto %s in (%s): %s)jedi.inferencerL   rJ   filter_namer   dbg)r   rH   name_contextanalysis_errorsrL   filtersnamess          r   gotozHelperValueMixin.gotoE   s?    )))+6""7K8		/dEJr   c                 Z   || }| j                  |||      }t        j                  d |D              }|s/t        |t              r|j
                  n|}| j                  |      }|s-|s+|r)t        |t              rddlm} |j                  || |       t        j                  d||       |S )zZ
        :param position: Position of the last statement -> tuple of line, column
        c              3   <   K   | ]  }|j                           y wr   r4   )r7   names     r   r9   z6HelperValueMixin.py__getattribute__.<locals>.<genexpr>T   s     #CTDJJL#Cr:   r   analysisz context.names_to_types: %s -> %s)rT   r(   r<   rD   r   r   py__getattribute__alternativesrM   rY   add_attribute_errorr   rO   )	r   rH   rP   positionrQ   rS   valuesnrY   s	            r   py__getattribute__z#HelperValueMixin.py__getattribute__L   s    
 L		+|_E###CU#CC%/T%B!!A88;FV+t,3,, $5		4eVDr   c                 t    | j                  d      }|st        j                  d|        |j                         S )N	__await__z"Tried to run __await__ on value %s)r_   r   warningr*   )r   await_value_sets     r   py__await__zHelperValueMixin.py__await__a   s3    11+>MM>E2244r   c                 .    | j                   j                  S r   )rW   string_namer-   s    r   
py__name__zHelperValueMixin.py__name__g   s    yy$$$r   c                 N   t        j                  d|        |r}ddlm} t	         || j                  d      j                         j                  d      j                         j                  d      j                         j                               g      S | j                  |      S )Nz
iterate %sr   )LazyKnownValues	__aiter__	__anext__ra   )	r   rO   jedi.inference.lazy_valueri   iterr_   r*   py__stop_iteration_returns
py__iter__)r   r>   r?   ri   s       r   r=   zHelperValueMixin.iteratej   s    		,%A ++K8LLN++K89L9L9N++K89L9L9N335	   233r   c                 &   t        j                  d| d|d      5  | j                         D ]4  }|j                  |      st        j                  dd        d d d        y t        j                  dd       	 d d d        y# 1 sw Y   y xY w)	Nzsubclass matching of z <=> BLUE)colorzmatched subclass TrueTzmatched subclass FalseF)r   increase_indent_cm	py__mro__is_same_classrO   )r   class_valueclss      r   is_sub_class_ofz HelperValueMixin.is_sub_class_ofz   s    %%$P[&\,24 	~~'  $$[1II5VD	 	  II.f=	 	 	s   %BB%BBc                 z    t        |      j                  t        j                  k7  r|j                  |       S | |k(  S r   )typeru   r   )r   class2s     r   ru   zHelperValueMixin.is_same_class   s6    <%%)9)G)GG''--v~r   c                 &     | j                   |i |S r   )_as_contextr   argskwargss      r   r   zHelperValueMixin.as_context   s    t000r   NF)NT)NNT)r   r   r   r   r#   r*   r.   r1   r@   rJ   rT   r_   rd   rg   r=   rx   ru   r   r   r   r   r   r   r      sg    )G=
* 
+ KO+/*5%4  1 1r   r   c                       e Zd ZdZdZdZdZd"dZd Zd Z	d"dZ
d"dZd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZefdZd Zd Zd Zd Zd Zd Zd Z d Z!d Z"e#d        Z$d#d Z%d! Z&y)$Valuez*
    To be implemented by subclasses.
    Nnot_defined_please_report_bugc                      || _         || _        y r   )r"   r   )r   r"   r   s      r   __init__zValue.__init__   s    .,r   c                 r    ddl m} |j                  |j                  d|j                  d| z         t
        S )Nr   rX   ztype-error-not-subscriptablez+TypeError: '%s' object is not subscriptablemessage)rM   rY   r   contextnode	NO_VALUES)r   index_value_setr>   rY   s       r   py__getitem__zValue.py__getitem__   s;    +''*$$ADH	 	 	
 r   c                     t         r   r	   )r   indexs     r   py__simple_getitem__zValue.py__simple_getitem__   s    ##r   c                     |2ddl m} |j                  |j                  d|j                  d| z         t        g       S )Nr   rX   ztype-error-not-iterablez&TypeError: '%s' object is not iterabler   )rM   rY   r   r   r   rm   )r   r>   rY   s      r   ro   zValue.py__iter__   sE    */LL#++)#((@4G	  I
 Bxr   c                 $    | j                  |      S r   )ro   )r   r>   s     r   
py__next__zValue.py__next__   s    233r   c                     g S r   r   r-   s    r   get_signatureszValue.get_signatures   s    	r   c                      yr   r   r-   s    r   is_classzValue.is_class       r   c                      yr   r   r-   s    r   is_class_mixinzValue.is_class_mixin   r   r   c                      yr   r   r-   s    r   is_instancezValue.is_instance   r   r   c                      yr   r   r-   s    r   is_functionzValue.is_function   r   r   c                      yr   r   r-   s    r   	is_modulezValue.is_module   r   r   c                      yr   r   r-   s    r   is_namespacezValue.is_namespace   r   r   c                      yr   r   r-   s    r   is_compiledzValue.is_compiled   r   r   c                      yr   r   r-   s    r   is_bound_methodzValue.is_bound_method   r   r   c                      yr   r   r-   s    r   is_builtins_modulezValue.is_builtins_module   r   r   c                      y)z
        Since Wrapper is a super class for classes, functions and modules,
        the return value will always be true.
        Tr   r-   s    r   
py__bool__zValue.py__bool__   s    
 r   c                 x    	 | j                   j                   t        | j                         S # t        $ r Y yw xY w)N )	tree_nodeget_doc_noder   AttributeErrorr-   s    r   	py__doc__zValue.py__doc__   s9    	9NN'' )88  		s   - 	99c                 2    |t         u rt        d| z        |S )Nz'There exists no safe value for value %s)sentinel
ValueError)r   defaults     r   get_safe_valuezValue.get_safe_value   s     hFMNNr   c                 >    t        j                  d|| |       t        S )Nz!%s not possible between %s and %sr   rb   r   )r   otheroperators      r   execute_operationzValue.execute_operation   s    98T5Qr   c                 :    t        j                  d|        t        S )Nzno execution possible %sr   r$   s     r   
py__call__zValue.py__call__   s    0$7r   c                 :    t        j                  d|        t        S )Nz0Not possible to return the stop iterations of %sr   r-   s    r   rn   z Value.py__stop_iteration_returns   s    H$Or   c                     t         S )zH
        For now a way to add values in cases like __getattr__.
        )r   )r   rH   s     r   rZ   z$Value.py__getattribute__alternatives   s
     r   c                 F    t        j                  d|        t        | g      S )NzNo __get__ defined on %s)r   rb   r(   )r   instancerv   s      r   	py__get__zValue.py__get__   s    0$7r   c                     t         S r   )NotImplemented)r   calling_instancer   rv   s       r   py__get__on_classzValue.py__get__on_class   s    r   c                      y r   r   r-   s    r   get_qualified_nameszValue.get_qualified_names  s    r   c                 6    | j                   j                         S r   )r   rF   r-   s    r   rF   zValue.is_stub  s    ""**,,r   c                     t         r   )r   r-   s    r   r}   zValue._as_context  s    r   c                     t         r   NotImplementedErrorr-   s    r   rW   z
Value.name  s    !!r   c                      y r   r   )r   add_class_infos     r   get_type_hintzValue.get_type_hint  s    r   c                     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_sets     r   infer_type_varszValue.infer_type_vars  s	    6 	r   r   T)'r   r   r   __doc__r   
array_typeapi_typer   r   r   ro   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rn   rZ   r   r   r   rF   r}   propertyrW   r   r   r   r   r   r   r      s     I J.H-	$49 &. 
 - " "r   r   Nc                 \    t         j                  d | j                  ||      D              S )z
    Calls `iterate`, on all values but ignores the ordering and just returns
    all values that the iterate functions yield.
    c              3   <   K   | ]  }|j                           y wr   r4   r6   s     r   r9   z!iterate_values.<locals>.<genexpr>8  s!       	r:   r?   r;   )r]   r>   r?   s      r   iterate_valuesr   3  s2    
   ..)<x.P  r   c                   F    e Zd Zed        Ze e       d               Zd Zy)_ValueWrapperBasec                     ddl m} | j                  j                  }|j                   || |j                        S ddlm}  || |j                        S )Nr   )	ValueName)CompiledValueName)jedi.inference.namesr   _wrapped_valuerW   	tree_namejedi.inference.compiledr   rf   )r   r   wrapped_namer   s       r   rW   z_ValueWrapperBase.name?  sK    2**//!!-T<#9#9::A$T<+C+CDDr   c                      | |i |S r   r   )rw   r"   r   r   s       r   create_cachedz_ValueWrapperBase.create_cachedI  s     D#F##r   c                 F    |dk7  sJ d       t        | j                  |      S )Nr   zProblem with _get_wrapped_value)getattrr   )r   rW   s     r   __getattr__z_ValueWrapperBase.__getattr__N  s*    ''J)JJ't**D11r   N)	r   r   r   r   rW   classmethodr   r   r   r   r   r   r   r   >  s:    E E *,$ - $2r   r   c                   2    e Zd Zeed               Zd Zd Zy)LazyValueWrapperc                 x    t        j                  d      5  | j                         cd d d        S # 1 sw Y   y xY w)NzResolve lazy value wrapper)r   rs   _get_wrapped_valuer-   s    r   r   zLazyValueWrapper._wrapped_valueT  s4     %%&BC 	-**,	- 	- 	-s   09c                 4    d| j                   j                  z  S )Nz<%s>)	__class__r   r-   s    r   __repr__zLazyValueWrapper.__repr__Z  s    0011r   c                     t         r   r   r-   s    r   r   z#LazyValueWrapper._get_wrapped_value]  s    !!r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   S  s&    -  -2"r   r   c                       e Zd Zd Zd Zy)ValueWrapperc                     || _         y r   )r   )r   wrapped_values     r   r   zValueWrapper.__init__b  s
    +r   c                 N    | j                   j                  d| j                  dS )N())r   r   r   r-   s    r   r   zValueWrapper.__repr__e  s    >>22D4G4GHHr   N)r   r   r   r   r   r   r   r   r   r   a  s    ,Ir   r   c                   $     e Zd Z fdZd Z xZS )	TreeValuec                 4    t         |   ||       || _        y r   )superr   r   )r   r"   r   r   r   s       r   r   zTreeValue.__init__j  s    .9"r   c                 P    d| j                   j                  d| j                  dS )N<: >)r   r   r   r-   s    r   r   zTreeValue.__repr__n  s    !^^44dnnEEr   )r   r   r   r   r   __classcell__)r   s   @r   r   r   i  s    #Fr   r   c                   $    e Zd Zd Zd Zd Zd Zy)ContextualizedNodec                      || _         || _        y r   )r   r   )r   r   r   s      r   r   zContextualizedNode.__init__s  s    	r   c                 6    | j                   j                         S r   )r   r   r-   s    r   r   z#ContextualizedNode.get_root_contextw  s    ||,,..r   c                 L    | j                   j                  | j                        S r   )r   
infer_noder   r-   s    r   r5   zContextualizedNode.inferz  s    ||&&tyy11r   c                 j    d| j                   j                  d| j                  d| j                  dS )Nr  r  z in r  )r   r   r   r   r-   s    r   r   zContextualizedNode.__repr__}  s!    #'>>#:#:DIIt||TTr   N)r   r   r   r   r   r5   r   r   r   r   r  r  r  s    /2Ur   r  c                    t         }t               }|D ]a  }|j                  d       }t        |      t        t
        t        t        t        fv r	 || j                  |      z  }Q|j                  |       c |s|s|| j                  t        |      |      z  }t        j                  d|       |S # t        $ r Y Xw xY w)N)r   zpy__getitem__ result: %s)r   setr   rz   floatintstrslicebytesr   r
   r   r   r(   r   rO   )r   index_valuesr>   resultunused_valuesindex_valuer   s          r   _getitemr    s    FEM# 	'**4*8;5#sE599%44U;; 	+&	' L%%%]#
 	
 
II(&1M ) s   B11	B=<B=c                       e Zd Zd Zed        Zed        Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd ZddZd Zd Zd Zd Zd Zd Zd Zd ZddZd Zy)r(   c                 V    t        |      | _        |D ]  }t        |t              sJ  y r   )	frozenset_setrD   r(   )r   iterabler   s      r   r   zValueSet.__init__  s-    h'	 	3E!%222	3r   c                 6    | j                  |       }||_        |S r   )__new__r  )rw   
frozenset_r   s      r   _from_frozen_setzValueSet._from_frozen_set  s    {{3	r   c                     t               }|D ]0  }t        |t              r||j                  z  }#|t	        |      z  }2 | j                  t	        |            S )z7
        Used to work with an iterable of set.
        )r  rD   r(   r  r  r   )rw   sets
aggregatedset_s       r   r<   zValueSet.from_sets  sX    
 U
 	.D$)dii'
io-
		.
 ##Ij$9::r   c                 R    | j                  | j                  |j                  z        S r   r   r  r   r   s     r   __or__zValueSet.__or__       $$TYY%;<<r   c                 R    | j                  | j                  |j                  z        S r   r&  r'  s     r   __and__zValueSet.__and__  r)  r   c                 ,    t        | j                        S r   )rm   r  r-   s    r   __iter__zValueSet.__iter__      DIIr   c                 ,    t        | j                        S r   )boolr  r-   s    r   __bool__zValueSet.__bool__  r.  r   c                 ,    t        | j                        S r   )lenr  r-   s    r   __len__zValueSet.__len__  s    499~r   c                 L    ddj                  d | j                  D              z  S )NzS{%s}, c              3   2   K   | ]  }t        |        y wr   )r  )r7   ss     r   r9   z$ValueSet.__repr__.<locals>.<genexpr>  s     #>qCF#>s   )joinr  r-   s    r   r   zValueSet.__repr__  s     $))#>DII#>>??r   c                 L    | j                  t        || j                              S r   )r   filterr  )r   filter_funcs     r   r;  zValueSet.filter  s    ~~f[$))<==r   c                       fd}|S )Nc                  T     j                   fdj                  D              S )Nc              3   B   K   | ]  } t        |      i   y wr   )r   )r7   r   r   r   rW   s     r   r9   z7ValueSet.__getattr__.<locals>.mapper.<locals>.<genexpr>  s,      " %t$d5f5"   )r<   r  )r   r   rW   r   s   ``r   mapperz$ValueSet.__getattr__.<locals>.mapper  s%    >> "!YY"  r   r   )r   rW   rA  s   `` r   r   zValueSet.__getattr__  s    	
 r   c                 4    | j                   |j                   k(  S r   )r  r'  s     r   __eq__zValueSet.__eq__  s    yyEJJ&&r   c                 &    | j                  |       S r   )rC  r'  s     r   __ne__zValueSet.__ne__  s    ;;u%%%r   c                 ,    t        | j                        S r   )hashr  r-   s    r   __hash__zValueSet.__hash__  r.  r   c                 :    t        d | j                  D              S )Nc              3   <   K   | ]  }|j                           y wr   )py__class__)r7   rI   s     r   r9   z'ValueSet.py__class__.<locals>.<genexpr>  s     ;A;r:   )r(   r  r-   s    r   rK  zValueSet.py__class__  s    ;;;;r   Nc              #      K   ddl m} | j                  D cg c]  }|j                  ||       }}t	        | D ]  } ||D cg c]  }||	 c}        y c c}w c c}w w)Nr   )get_merged_lazy_valuer   )rl   rM  r  r=   r   )r   r>   r?   rM  rI   
type_iterslazy_valuesls           r   r=   zValueSet.iterate  sn     CQUQZQZ[Aaii 3hiG[
[&
3 	K''9q1=9 	 \ :s!   A&AA&A!
A!
A&c                 T    t         j                  fd| j                  D              S )Nc              3   V   K   | ]   }|j                   j                  |       " y wr   r!   )r7   rI   r    s     r   r9   z#ValueSet.execute.<locals>.<genexpr>  s$     !]a!"3"3";";Ay"I!]s   &)r(   r<   r  r$   s    `r   r#   zValueSet.execute  s!    !!!]SWS\S\!]]]r   c                 X    t         j                  fd| j                  D              S )Nc              3   B   K   | ]  } |j                   i   y wr   r,   r7   rI   r   r   s     r   r9   z/ValueSet.execute_with_values.<locals>.<genexpr>  s$     !\Q"7!"7"7"H"H!\r@  rS  r~   s    ``r   r*   zValueSet.execute_with_values  s!    !!!\RVR[R[!\\\r   c                 ~    t        t        | j                  D cg c]  } |j                  |i | c}g       S c c}w r   )r   r   r  rT   )r   r   r   rI   s       r   rT   zValueSet.goto  s3    cTYYGFAFFD3F3GLLGs   :
c                 X    t         j                  fd| j                  D              S )Nc              3   B   K   | ]  } |j                   i   y wr   )r_   rV  s     r   r9   z.ValueSet.py__getattribute__.<locals>.<genexpr>  s$     ![A"6!"6"6"G"G![r@  rS  r~   s    ``r   r_   zValueSet.py__getattribute__  s!    !!![QUQZQZ![[[r   c                 X    t         j                  fd| j                  D              S )Nc              3   <   K   | ]  }t        |gi   y wr   )r  rV  s     r   r9   z$ValueSet.get_item.<locals>.<genexpr>  s      !R1(1">t">v">!Rs   rS  r~   s    ``r   get_itemzValueSet.get_item  s    !!!R		!RRRr   c                     | j                  g       }| j                  D ]  }	 t        ||      }| |       z  } |S # t        $ r Y )w xY wr   )r   r  r   r   )r   function_namer   rI   methods        r   	try_mergezValueSet.try_merge  s^    NN2&	 	&A& M2 VX%		& 	 " s   <	AAc                     t         j                  | j                  D cg c]  }|j                          c}      S c c}w r   )r(   r<   r  r1   )r   rI   s     r   r1   z"ValueSet.gather_annotation_classes   s.    !!$))"TQ1#>#>#@"TUU"Ts   <c                 p    | j                   D cg c]  }|j                         D ]  }|  c}}S c c}}w r   )r  r   )r   rI   sigs      r   r   zValueSet.get_signatures  s/    !YYE!2B2B2DE3EEEEs   2c                 \   | j                   D cg c]  }|j                  |       }}t        t        d |            }t	        |      dk(  r|d   S d|v }|r|j                  d       t	        |      dk(  ry t	        |      dk(  r|d   }nddj                  |      z  }|rd|z  }|S c c}w )N)r      r   Nonez	Union[%s]r6  zOptional[%s])r  r   sortedr;  r3  remover9  )r   r   vt
type_hintsoptionalr8  s          r   r   zValueSet.get_type_hint  s    EIYYOQ__N_;OOF4O,
z?aa= Z'f%z?a_!1Adii
33A"A# Ps   B)c                 h    ddl m} i }| j                  D ]  } |||j                  |              |S )Nr   )merge_type_var_dicts)!jedi.inference.gradual.annotationrn  r  r   )r   r   rn  type_var_dictr   s        r   r   zValueSet.infer_type_vars  s>    JYY 	E %%i0	
 r   r   r   )r   r   r   r   r   r   r<   r(  r+  r-  r1  r4  r   r;  r   rC  rE  rH  rK  r=   r#   r*   rT   r_   r\  r`  r1   r   r   r   r   r   r   r(   r(     s    3
  
 
; 
;==@>'&<^]M\S	VF(
r   r(   c                       fd}|S )Nc                  &    t         | i |      S r   r0   )r   r   funcs     r   wrapperz&iterator_to_value_set.<locals>.wrapper+  s    d-f-..r   r   )rs  rt  s   ` r   iterator_to_value_setru  *  s    / Nr   r   )%r   	functoolsr   r   r   	itertoolsr   parso.python.treer   jedir   jedi.parser_utilsr   jedi.inference.helpersr
   jedi.inference.utilsr   jedi.inference.cacher   
jedi.cacher   objectr   	Exceptionr   r   r   r   r   r   r   r   r  r  r(   r   ru  r   r   r   <module>r     s      ! "  3 8 . F %8	9 	o1 o1da aH2( 2*"( "I$ IF FU U6H HV RL	r   