o
    ð›hg  ã                   @   sÖ   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	d
„ Zeed�ejdd„ ƒƒZdd„ ZG dd„ de	ƒZG dd„ de
ƒZG dd„ deƒZG d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                 C   s   |j dvrtS t| |ƒS )zI Just a mapper function for the internal _internal_check_array_additions )ÚlistÚset)Z
array_typer   Ú_internal_check_array_additions)ÚcontextÚsequence© r   úYc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/value/dynamic_arrays.pyÚcheck_array_additions"   s   

r   )Údefaultc              
      sÌ  ddl m‰  tjd| dd� |  ¡ }tjr| ¡ r#tjddd� tS ‡ fdd„}tj	d	}t_	|j
jd
k}|r<g d¢nddg}tƒ }|D ]“}z	|j ¡ | }	W n	 tyY   Y qEw |	D ]{}
| j}|j|
j  k rn|jk spn q\|
j}|j}|j |¡}z	|j|d  }W n	 tyŽ   Y q\w |jdks¢|jd dks¢|jd dkr£q\|  |
¡}t | j|¡� }|rÈt||
dd�}||v rÈ||||jd |ƒO }W d  ƒ n1 sÒw   Y  q\qE|t_	tjd|dd� |S )zr
    Checks if a `Array` has "add" (append, insert, extend) statements:

    >>> a = [""]
    >>> a.append(1)
    r   ©Ú	argumentszDynamic array search for %sZMAGENTA)ÚcolorzDynamic array search aborted.c                    s„   t ˆ  | j| |¡ ¡ ƒ}tƒ }|dv r|dd … }|dv r+|D ]	\}}| |¡ q|S |dv r@|D ]\}}|t| ¡  ¡ ƒO }q1|S )N)Úinserté   )ÚappendÚaddr   )ÚextendÚupdate)r   ÚTreeArgumentsÚinference_stateÚunpackr   r   ÚinferÚiterate)r   ZarglistÚadd_nameÚparamsÚresultÚkeyÚ
lazy_valuer   r   r   Úfind_additions<   s   ýz7_internal_check_array_additions.<locals>.find_additionsFr   )r   r   r   r   r   r   Útrailerú(ú)T)Zcut_own_trailerNzDynamic array result %s)Újedi.inferencer   r   ZdbgZget_root_contextr   Zdynamic_array_additionsZis_compiledr   Z dynamic_params_for_other_modulesÚnameZstring_namer   Z	tree_nodeZget_used_namesÚKeyErrorÚ	start_posÚend_posÚparentÚchildrenÚindexÚ
IndexErrorÚtypeZcreate_contextr   Zexecution_allowedr   r
   )r   r   Zmodule_contextr(   Ztemp_param_addZis_listZsearch_namesZadded_typesr#   Zpossible_namesr-   Z
value_noder)   ÚpowerZtrailer_posZexecution_trailerZrandom_contextÚallowedÚfoundr   r   r   r   +   sn   	ÿÿÿ

ýý€÷€í#r   c                 C   s(   t | |ƒ}ddlm} | t|gƒg¡S )z$Used for set() and list() instances.r   r   )Ú_DynamicArrayAdditionsr,   r   ZValuesArgumentsr   )Úinstancer   Zair   r   r   Úget_dynamic_array_instance~   s   
r;   c                   @   s4   e Zd ZdZdd„ Zdd„ Zddd„Zdd
d„ZdS )r9   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                 C   s   || _ || _d S ©N)Ú	_instanceÚ
_arguments)Úselfr:   r   r   r   r   Ú__init__�   s   
z_DynamicArrayAdditions.__init__c                 C   s   | j jj d¡\}|S )NÚtuple)r=   r   Zbuiltins_moduleZpy__getattribute__)r?   Útuple_r   r   r   Úpy__class__“   s   z"_DynamicArrayAdditions.py__class__Nc                 c   sx   � | j }z
t| ¡ ƒ\}}W n	 ty   Y n
w | ¡  ¡ E d H  ddlm} t||ƒr:t	|j
| jƒ}|E d H  d S d S )Nr   )r   )r>   Únextr    ÚStopIterationr!   r"   Zjedi.inference.argumentsr   Ú
isinstancer   r   r=   )r?   Úcontextualized_noder   Ú_r'   r   Ú	additionsr   r   r   Ú
py__iter__—   s   €ÿ
þz!_DynamicArrayAdditions.py__iter__Fc                 C   s
   |   |¡S r<   )rJ   )r?   rG   Úis_asyncr   r   r   r"   ¥   s   
z_DynamicArrayAdditions.iterater<   )NF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r@   rC   rJ   r"   r   r   r   r   r9   …   s    	
r9   c                       s,   e Zd Z‡ fdd„Zdd„ Zdd„ Z‡  ZS )Ú_Modificationc                    s   t ƒ  |¡ || _|| _d S r<   )Úsuperr@   Ú_assigned_valuesÚ_contextualized_key)r?   Zwrapped_valueZassigned_valuesZcontextualized_key©Ú	__class__r   r   r@   ª   s   
z_Modification.__init__c                 O   s   | j j|i |¤Ž| jB S r<   )Ú_wrapped_valueÚpy__getitem__rR   )r?   ÚargsÚkwargsr   r   r   rW   ¯   s   z_Modification.py__getitem__c                 C   s.   dd„ | j  ¡ D ƒ}||v r| jS | j |¡S )Nc                 S   s   g | ]}|  t¡‘qS r   )Zget_safe_valueÚ	_sentinel)Ú.0Úvr   r   r   Ú
<listcomp>³   s    ÿÿz6_Modification.py__simple_getitem__.<locals>.<listcomp>)rS   r!   rR   rV   Úpy__simple_getitem__)r?   r3   Úactualr   r   r   r^   ²   s   þz"_Modification.py__simple_getitem__)rL   rM   rN   r@   rW   r^   Ú__classcell__r   r   rT   r   rP   ©   s    rP   c                   @   s   e Zd Zddd„Zdd„ ZdS )ÚDictModificationNc                 c   s    � | j  |¡E d H  | jV  d S r<   )rV   rJ   rS   ©r?   rG   r   r   r   rJ   ½   s   €zDictModification.py__iter__c                 C   s   | j  ¡ | j ¡ B S r<   )rV   Úget_key_valuesrS   r!   )r?   r   r   r   rc   Á   s   zDictModification.get_key_valuesr<   )rL   rM   rN   rJ   rc   r   r   r   r   ra   ¼   s    
ra   c                   @   s   e Zd Zddd„ZdS )ÚListModificationNc                 c   s$   � | j  |¡E d H  t| jƒV  d S r<   )rV   rJ   r	   rR   rb   r   r   r   rJ   Æ   s   €zListModification.py__iter__r<   )rL   rM   rN   rJ   r   r   r   r   rd   Å   s    rd   N)rO   Zjedir   r   r,   r   Zjedi.inference.base_valuer   r   r   r   Zjedi.inference.lazy_valuer	   Zjedi.inference.helpersr
   Zjedi.inference.cacher   ÚobjectrZ   r   Zincrease_indentr   r;   r9   rP   ra   rd   r   r   r   r   Ú<module>   s$    	Q$	