
    fg                        d 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	m
Z
 ddlmZ ddlmZ ddlmZ  e       Zd	 Z ee
      ej(                  d               Zd Z G d de	      Z G d de
      Z G d de      Z G d de      Zy)a  
A module to deal with stuff like `list.append` and `set.add`.

Array modifications
*******************

If the content of an array (``set``/``list``) is requested somewhere, the
current module will be checked for appearances of ``arr.append``,
``arr.insert``, etc.  If the ``arr`` name points to an actual array, the
content will be added

This can be really cpu intensive, as you can imagine. Because |jedi| has to
follow **every** ``append`` and check whether it's the right array. However this
works pretty good, because in *slow* cases, the recursion detector and other
settings will stop this process.

It is important to note that:

1. Array modifications work only in the current module.
2. Jedi only checks Array additions; ``list.pop``, etc are ignored.
    )debug)settings)	recursion)ValueSet	NO_VALUESHelperValueMixinValueWrapper)LazyKnownValues)infer_call_of_leaf)inference_state_method_cachec                 B    |j                   dvrt        S t        | |      S )zI Just a mapper function for the internal _internal_check_array_additions )listset)
array_typer   _internal_check_array_additions)contextsequences     ^/var/www/cvtools/html/venv/lib/python3.12/site-packages/jedi/inference/value/dynamic_arrays.pycheck_array_additionsr   "   s#    /1*7H==    )defaultc           	         ddl m t        j                  d|z  d       | j	                         }t
        j                  r|j                         rt        j                  dd       t        S fd}t
        j                  dc}t
        _	        |j                  j                  d	k(  }|rg d
nddg}t               }|D ]D  }	 |j                  j                         |   }	|	D ]  }
| j                  }|j                  |
j                  cxk  r|j                   k  sn <|
j"                  }|j"                  }|j$                  j'                  |      }	 |j$                  |dz      }|j(                  dk7  s$|j$                  d   dk7  s|j$                  d   dk(  r| j-                  |
      }t/        j0                  | j2                  |      5 }|r,t5        ||
d      }||v r| |||j$                  d   |      z  }ddd         G |t
        _	        t        j                  d|d       |S # t*        $ r Y Uw xY w# 1 sw Y   cxY w# t6        $ r Y w xY w)zr
    Checks if a `Array` has "add" (append, insert, extend) statements:

    >>> a = [""]
    >>> a.append(1)
    r   	argumentszDynamic array search for %sMAGENTA)colorzDynamic array search aborted.c                 H   t        j                  | j                  | |      j                               }t	               }|dv r|dd  }|dv r|D ]  \  }}|j                  |        |S |dv r4|D ]/  \  }}|t	        |j                         j                               z  }1 |S )N)insert   )appendaddr   )extendupdate)r   TreeArgumentsinference_stateunpackr   r!   inferiterate)r   arglistadd_nameparamsresultkey
lazy_valuer   s          r   find_additionsz7_internal_check_array_additions.<locals>.find_additions<   s    i--g.E.EwPWX__abz!ABZF22#) 'Z

:&'
  --#) <Z#j..088:;;<r   Fr   )r    r"   r   r!   r#   r   trailer()T)cut_own_trailerNzDynamic array result %s)jedi.inferencer   r   dbgget_root_contextr   dynamic_array_additionsis_compiledr    dynamic_params_for_other_modulesnamestring_namer   	tree_nodeget_used_names	start_posend_posparentchildrenindextype
IndexErrorcreate_contextr   execution_allowedr%   r   KeyError)r   r   module_contextr/   temp_param_addis_listsearch_namesadded_typesr*   possible_namesr:   
value_noder0   powertrailer_posexecution_trailerrandom_contextallowedfoundr   s                      @r   r   r   +   sN    )	II+h6iH--/N++~/I/I/K		1C 	115 >NH= mm''61G6=2E8CTL%K  &%	+55DDFxPN '  $..
",,t~~R
@R@RR++#nn227;!(-{Q(G% )--:099!<C099!<C !(!7!7!=001H1H%P T[ 2* ,0!
 $u,'> . 1 : :1 = (, K ' &R 1?H-	II'IF9 "  -  		s0   I	H,
/H<,	H98H9<I		IIc                 ^    t        | |      }ddlm} |j                  t	        |g      g      S )z$Used for set() and list() instances.r   r   )_DynamicArrayAdditionsr4   r   ValuesArgumentsr   )instancer   ais      r   get_dynamic_array_instancerZ   ~   s+    	)	4B($$htn%566r   c                   ,    e Zd ZdZd Zd ZddZddZy)	rV   aj  
    Used for the usage of set() and list().
    This is definitely a hack, but a good one :-)
    It makes it possible to use set/list conversions.

    This is not a proper context, because it doesn't have to be. It's not used
    in the wild, it's just used within typeshed as an argument to `__init__`
    for set/list and never used in any other place.
    c                      || _         || _        y N)	_instance
_arguments)selfrX   r   s      r   __init__z_DynamicArrayAdditions.__init__   s    !#r   c                 h    | j                   j                  j                  j                  d      \  }|S )Ntuple)r^   r%   builtins_modulepy__getattribute__)r`   tuple_s     r   py__class__z"_DynamicArrayAdditions.py__class__   s*    ..00@@SST[\r   Nc              #   J  K   | j                   }	 t        |j                               \  }}|j                         j	                         E d {    ddlm} t        ||      r+t        |j                  | j                        }|E d {    y y 7 B# t
        $ r Y Kw xY w7 w)Nr   )r$   )r_   nextr&   r'   r(   StopIterationjedi.inference.argumentsr$   
isinstancer   r   r^   )r`   contextualized_noder   _r.   r$   	additionss          r   
py__iter__z!_DynamicArrayAdditions.py__iter__   s     OO		4 !1!1!34MAz "'')11333:i/7	8I8I4>>ZI    0 4  		 !s?   B#B !B#B;B#	B!
B#	BB#BB#c                 $    | j                  |      S r]   )rp   )r`   rm   is_asyncs      r   r(   z_DynamicArrayAdditions.iterate   s    233r   r]   )NF)__name__
__module____qualname____doc__ra   rg   rp   r(    r   r   rV   rV      s    $!4r   rV   c                   *     e Zd Z fdZd Zd Z xZS )_Modificationc                 @    t         |   |       || _        || _        y r]   )superra   _assigned_values_contextualized_key)r`   wrapped_valueassigned_valuescontextualized_key	__class__s       r   ra   z_Modification.__init__   s     ' /#5 r   c                 T     | j                   j                  |i || j                  z  S r]   )_wrapped_valuepy__getitem__r|   )r`   argskwargss      r   r   z_Modification.py__getitem__   s+    0t""00$A&ADDYDYYYr   c                     | j                   j                         D cg c]  }|j                  t               }}||v r| j                  S | j
                  j                  |      S c c}w r]   )r}   r'   get_safe_value	_sentinelr|   r   py__simple_getitem__)r`   rB   vactuals       r   r   z"_Modification.py__simple_getitem__   sl     --335
 Y'
 
 F?(((""77>>
s   A&)rs   rt   ru   ra   r   r   __classcell__)r   s   @r   ry   ry      s    6
Z?r   ry   c                       e Zd ZddZd Zy)DictModificationNc              #   r   K   | j                   j                  |      E d {    | j                   y 7 wr]   )r   rp   r}   r`   rm   s     r   rp   zDictModification.py__iter__   s3     &&112EFFF&&& 	Gs   757c                 l    | j                   j                         | j                  j                         z  S r]   )r   get_key_valuesr}   r'   )r`   s    r   r   zDictModification.get_key_values   s+    ""113d6N6N6T6T6VVVr   r]   )rs   rt   ru   rp   r   rw   r   r   r   r      s    'Wr   r   c                       e Zd ZddZy)ListModificationNc              #      K   | j                   j                  |      E d {    t        | j                         y 7 wr]   )r   rp   r
   r|   r   s     r   rp   zListModification.py__iter__   s8     &&112EFFFd3344 	Gs   A >A r]   )rs   rt   ru   rp   rw   r   r   r   r      s    5r   r   N)rv   jedir   r   r4   r   jedi.inference.base_valuer   r   r   r	   jedi.inference.lazy_valuer
   jedi.inference.helpersr   jedi.inference.cacher   objectr   r   increase_indentr   rZ   rV   ry   r   r   rw   r   r   <module>r      s   *   $  5 5 =H	> i0N  1Nb7!4- !4H?L ?&W} W5} 5r   