
    ^hg                        S r SSKJr  SSKJr  SSKJr  SSKJrJrJ	r	J
r
  SSKJr  SSKJr  SSKJr  \" 5       rS	 r\" \S
9\R(                  S 5       5       rS r " S S\	5      r " S S\
5      r " S S\5      r " S S\5      rg)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                 D    UR                   S;  a  [        $ [        X5      $ )zHJust a mapper function for the internal _internal_check_array_additions )listset)
array_typer   _internal_check_array_additions)contextsequences     ]/home/james-whalen/.local/lib/python3.13/site-packages/jedi/inference/value/dynamic_arrays.pycheck_array_additionsr   "   s!    /1*7==    )defaultc           	        ^ SSK Jm  [        R                  " SU-  SS9  U R	                  5       n[
        R                  (       a  UR                  5       (       a  [        R                  " SSS9  [        $ U4S jn[
        R                  Ssn[
        l	        UR                  R                  S	:H  nU(       a  / S
QOSS/n[        5       nU GHS  n UR                  R                  5       U   n	U	 GH*  n
U R                  nUR                  U
R                  s=:  a  UR                   :  d  O  M?  U
R"                  nUR"                  nUR$                  R'                  U5      n UR$                  US-      nUR(                  S:w  d&  UR$                  S   S:w  d  UR$                  S   S:X  a  M   U R-                  U
5      n[.        R0                  " U R2                  U5       nU(       a*  [5        UU
SS9nUU;   a  Xs" UUR$                  S   U5      -  nSSS5        GM-     GMV     U[
        l	        [        R                  " SUSS9  U$ ! [*         a     GMe  f = f! , (       d  f       GMy  = f! [6         a     GM  f = f)zb
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                 V  > [        TR                  U R                  X5      R                  5       5      n[	        5       nUS;   a  USS  nUS;   a  U H  u  pVUR                  U5        M     U$ US;   a5  U H/  u  pVU[	        UR                  5       R                  5       5      -  nM1     U$ )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_additions7_internal_check_array_additions.<locals>.find_additions<   s    i--g.E.EwX__abz!ABZF22#)

:& $*
  --#)#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_noder1   powertrailer_posexecution_trailerrandom_contextallowedfoundr   s                      @r   r   r   +   sH    )	II+h6iH--/N++~/I/I/K/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   D ")!7!7!=001H1H%PT[ 2* ,0!
 $u,'> . 1 : :1 = (, K QP' ' !R 1?H-	II'IF9 "  QP-  		s0   I+"I2I
II
I(+
I:9I:c                 \    [        X5      nSSKJn  UR                  [	        U/5      /5      $ )z$Used for set() and list() instances.r   r   )_DynamicArrayAdditionsr5   r   ValuesArgumentsr   )instancer   ais      r   get_dynamic_array_instancer[   ~   s)    		4B($$htn%566r   c                   8    \ rS rSrSrS rS rS	S jrS
S jrSr	g)rW      aN  
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                     Xl         X l        g N)	_instance
_arguments)selfrY   r   s      r   __init___DynamicArrayAdditions.__init__   s    !#r   c                 h    U R                   R                  R                  R                  S5      u  nU$ )Ntuple)r`   r%   builtins_modulepy__getattribute__)rb   tuple_s     r   py__class__"_DynamicArrayAdditions.py__class__   s*    ..00@@SST[\r   Nc              #   R  #    U R                   n [        UR                  5       5      u  p4UR                  5       R	                  5        S h  vN   SSKJn  [        X%5      (       a+  [        UR                  U R                  5      nU S h  vN   g g  NF! [
         a     NPf = f N7f)Nr   )r$   )ra   nextr&   r'   r(   StopIterationjedi.inference.argumentsr$   
isinstancer   r   r`   )rb   contextualized_noder   _r.   r$   	additionss          r   
py__iter__!_DynamicArrayAdditions.py__iter__   s     OO		4 !1!1!34MA "'')11333:i//7	8I8I4>>ZI    0 4  		 !s?   B'B !B'B?B'B%B'
B"B'!B""B'c                 $    U R                  U5      $ r_   )rt   )rb   rq   is_asyncs      r   r(   _DynamicArrayAdditions.iterate   s    233r   )ra   r`   r_   )NF)
__name__
__module____qualname____firstlineno____doc__rc   rj   rt   r(   __static_attributes__ r   r   rW   rW      s    $!4r   rW   c                   4   ^  \ rS rSrU 4S jrS rS rSrU =r$ )_Modification   c                 <   > [         TU ]  U5        X l        X0l        g r_   )superrc   _assigned_values_contextualized_key)rb   wrapped_valueassigned_valuescontextualized_key	__class__s       r   rc   _Modification.__init__   s    ' /#5 r   c                 T    U R                   R                  " U0 UD6U R                  -  $ r_   )_wrapped_valuepy__getitem__r   )rb   argskwargss      r   r   _Modification.py__getitem__   s)    ""00$A&ADDYDYYYr   c                     U R                   R                  5        Vs/ s H  nUR                  [        5      PM     nnX;   a  U R                  $ U R
                  R                  U5      $ s  snf r_   )r   r'   get_safe_value	_sentinelr   r   py__simple_getitem__)rb   rC   vactuals       r   r   "_Modification.py__simple_getitem__   sm     --335
5 Y'5 	 
 ?(((""77>>
s   A*)r   r   )	ry   rz   r{   r|   rc   r   r   r~   __classcell__)r   s   @r   r   r      s    6
Z? ?r   r   c                   $    \ rS rSrSS jrS rSrg)DictModification   Nc              #   r   #    U R                   R                  U5       S h  vN   U R                  v   g  N7fr_   )r   rt   r   rb   rq   s     r   rt   DictModification.py__iter__   s2     &&112EFFF&&& 	Gs   757c                 l    U R                   R                  5       U R                  R                  5       -  $ r_   )r   get_key_valuesr   r'   )rb   s    r   r   DictModification.get_key_values   s+    ""113d6N6N6T6T6VVVr   r   r_   )ry   rz   r{   r|   rt   r   r~   r   r   r   r   r      s    'Wr   r   c                       \ rS rSrSS jrSrg)ListModification   Nc              #      #    U R                   R                  U5       S h  vN   [        U R                  5      v   g  N7fr_   )r   rt   r
   r   r   s     r   rt   ListModification.py__iter__   s7     &&112EFFFd3344 	Gs   A >A r   r_   )ry   rz   r{   r|   rt   r~   r   r   r   r   r      s    5r   r   N)r}   jedir   r   r5   r   jedi.inference.base_valuer   r   r   r	   jedi.inference.lazy_valuer
   jedi.inference.helpersr   jedi.inference.cacher   objectr   r   increase_indentr   r[   rW   r   r   r   r   r   r   <module>r      s   *   $  5 5 =H	> i0N  1Nb7!4- !4H?L ?&W} W5} 5r   