Ë
    ¬;jg  ã                   ó  — 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     út/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/jedi/inference/value/dynamic_arrays.pyÚcheck_array_additionsr   "   s#   € à×Ñ /Ñ1äÐä*¨7°HÓ=Ð=ó    )Ú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Ñ.EÀwÐPWÓX×_Ñ_ÓaÓbˆÜ“ˆØ�zÑ!Ø˜A˜B�ZˆFØÐ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   +   s=  ø€ õ )ä	‡I�IÐ+¨hÑ6¸iÕHØ×-Ñ-Ó/€NÜ×+Ò+¨~×/IÑ/IÔ/KÜ�	‰	Ð1¸ÕCÜÐôô 	×1Ñ1°5ð >€N”HÔ=ð �m‰m×'Ñ'¨6Ñ1€GÙ6=Ó2ÀEÈ8ÐCT€Lä“%€KÜ ˆð%	Ø+×5Ñ5×DÑDÓFÀxÑPˆNô '�Ø$×.Ñ.�
Ø"×,Ñ,¨t¯~©~ÔRÀ
×@RÑ@RÔRØØŸ+™+�ØŸ™�Ø#Ÿn™n×2Ñ2°7Ó;�ð!Ø(-¯©°{ÀQ±Ñ(GÐ%ð )×-Ñ-°Ò:Ø0×9Ñ9¸!Ñ<ÀÒCØ0×9Ñ9¸!Ñ<ÀÒCØ à!(×!7Ñ!7¸Ó!=�ä×0Ñ0°×1HÑ1HÈ%ÔPÐT[ÙÜ 2Ø*Ø Ø,0ô!˜ð
 $ uÑ,à'©>Ø .Ø 1× :Ñ :¸1Ñ =Ø (ó,ñ ˜K÷ QÑPò' 'ð !ðR 1?„HÔ-Ü	‡I�IÐ'¨¸IÕFØÐøô9 "ò Úðú÷ QÑPûô- ò 	Úð	ú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+   € ä	 ¨)Ó	4€BÝ(Ø×$Ñ$¤h°¨t£nÐ%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ÑSÐT[Ó\‰ˆØˆ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—   è ø€ Ø—O‘Oˆ	ð	4Ü  ×!1Ñ!1Ó!3Ó4‰MˆAˆzð "×'Ñ'Ó)×1Ñ1Ó3×3Ð3å:Ü�i Ô/Ü7¸	×8IÑ8IÈ4Ï>É>ÓZˆIØ × Ñ ð 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+   € Ø0ˆt×"Ñ"×0Ñ0°$ÐA¸&ÑAÀD×DYÑDYÑ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__²   so   € ð ×-Ñ-×3Ñ3Ô5ó
á5�ð ×ÑœYÕ'Ø5ð 	ð 
ð �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Ñ1Ð2EÓ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Ó3°d×6NÑ6N×6TÑ6TÓ6VÑ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Ñ1Ð2EÓ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Ð-ô !4ôH?�Lô ?ô&W�}ô Wô5�}õ 5r   