
    Mhg                     >   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dS )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     c/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jedi/inference/value/dynamic_arrays.pycheck_array_additionsr   "   s&    /11*7H===    )defaultc           	      h   ddl m t          j        d|z  d           |                                 }t
          j        r|                                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 ]S}	 |j                                        |         }	|	D ]}
| j        }|j        |
j        cxk     r|j        k     sn )|
j        }|j        }|j                            |          }	 |j        |dz            }|j        dk    s"|j        d         dk    s|j        d         dk    rn# t*          $ r Y w xY w|                     |
          }t/          j        | j        |          5 }|r1t5          ||
d          }||v r| |||j        d         |          z  }ddd           n# 1 swxY w Y   D# t6          $ r Y Qw xY w|t
          _	        t          j        d|d           |S )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                 ~   t                              | j        | |                                                    }t	                      }|dv r
|dd          }|dv r|D ]\  }}|                    |           nB|dv r>|D ];\  }}|t	          |                                                                          z  }<|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.EwPWXX__aabbz!!ABBZF222#) ' 'Z

:&&&&'---#) < <Z#j..0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   +   s    )(((((	I+h6iHHHH--//N+ ~/I/I/K/K 	1CCCC     	15 >NH= m'61G6=T2222E8CTL%%K  & &%	+5DDFFxPN '    $.
",t~RRRR
@RRRRR+#n227;;!(-{Q(G% )-::09!<CC09!<CC   D "   H ")!7!7!=!=01H%PP T[  2* ,0! ! !
 $u,,'>> . 1 :1 = (, , K              '   	 	 	H	L 1?H-	I'IFFFFs6   >G>1E00
E=<E=/4G//G36G3>
HHc                 v    t          | |          }ddlm} |                    t	          |g          g          S )z$Used for set() and list() instances.r   r   )_DynamicArrayAdditionsr4   r   ValuesArgumentsr   )instancer   ais      r   get_dynamic_array_instancerZ   ~   sB    	)	4	4B(((((($$htnn%5666r   c                   .    e Zd ZdZd Zd ZddZd	dZdS )
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                 "    || _         || _        d S N)	_instance
_arguments)selfrX   r   s      r   __init__z_DynamicArrayAdditions.__init__   s    !#r   c                 R    | 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@SST[\\r   Nc              #   P  K   | j         }	 t          |                                          \  }}|                                                                E d {V  n# t
          $ r Y nw xY wddlm} t          ||          r$t          |j
        | j                  }|E d {V  d S d S )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      O		4 !1!1!3!344MAz "''))113333333333  	 	 	D	
 	;:::::i// 	!7	8I4>ZZI          	! 	!s   $A 
A)(A)Fc                 ,    |                      |          S r]   )rp   )r`   rm   is_asyncs      r   r(   z_DynamicArrayAdditions.iterate   s    2333r   r]   )NF)__name__
__module____qualname____doc__ra   rg   rp   r(    r   r   rV   rV      sd         $ $ $  ! ! ! !4 4 4 4 4 4r   rV   c                   *     e Zd Z fdZd Zd Z xZS )_Modificationc                 f    t                                          |           || _        || _        d S r]   )superra   _assigned_values_contextualized_key)r`   wrapped_valueassigned_valuescontextualized_key	__class__s       r   ra   z_Modification.__init__   s1    ''' /#5   r   c                 6     | j         j        |i || j        z  S r]   )_wrapped_valuepy__getitem__r|   )r`   argskwargss      r   r   z_Modification.py__getitem__   s%    0t"0$A&AADDYYYr   c                     d | j                                         D             }||v r| j        S | j                            |          S )Nc                 B    g | ]}|                     t                    S rw   )get_safe_value	_sentinel).0vs     r   
<listcomp>z6_Modification.py__simple_getitem__.<locals>.<listcomp>   s6     
 
 
 Y''
 
 
r   )r}   r'   r|   r   py__simple_getitem__)r`   rB   actuals      r   r   z"_Modification.py__simple_getitem__   sZ    
 
-3355
 
 
 F??(("77>>>r   )rs   rt   ru   ra   r   r   __classcell__)r   s   @r   ry   ry      sY        6 6 6 6 6
Z Z Z? ? ? ? ? ? ?r   ry   c                       e Zd ZddZd ZdS )DictModificationNc              #   \   K   | j                             |          E d {V  | j        V  d S r]   )r   rp   r}   r`   rm   s     r   rp   zDictModification.py__iter__   sE      &112EFFFFFFFFF&&&&&&r   c                 h    | j                                         | j                                        z  S r]   )r   get_key_valuesr}   r'   )r`   s    r   r   zDictModification.get_key_values   s+    "1133d6N6T6T6V6VVVr   r]   )rs   rt   ru   rp   r   rw   r   r   r   r      s<        ' ' ' 'W W W W Wr   r   c                       e Zd ZddZdS )ListModificationNc              #   v   K   | j                             |          E d {V  t          | j                  V  d S r]   )r   rp   r
   r|   r   s     r   rp   zListModification.py__iter__   sM      &112EFFFFFFFFFd34444444r   r]   )rs   rt   ru   rp   rw   r   r   r   r      s(        5 5 5 5 5 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 5 5 5 5 5 5 5 5 5 5 = = = = = =FHH	> > > i000N N  10Nb7 7 7!4 !4 !4 !4 !4- !4 !4 !4H? ? ? ? ?L ? ? ?&W W W W W} W W W5 5 5 5 5} 5 5 5 5 5r   