a
    lcf                     @   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 modfications 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   _/var/www/html/django/DPS/env/lib/python3.9/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r4| rFtjddd tS  fdd}tj	d	 }t_	|j
jd
k}|rxg dnddg}t }|D ]:}z|j | }	W n ty   Y qY q0 |	D ]}
| j}|j|
j  k r|jk sq q|
j}|j}|j|}z|j|d  }W n ty*   Y qY n,0 |jdks|jd dks|jd dkrVq| |
}t| j|D}|rt||
dd}||v r||||jd |O }W d   q1 s0    Y  qq|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 r2|dd  }|dv rT|D ]\}}|| q>n*|dv r~|D ]\}}|t|  O }q`|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   +   sf    	






*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   sr   | j }zt| \}}W n ty,   Y n0 |  E d H  ddlm} t||rnt	|j
| j}|E d H  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.iterate)N)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_values)N)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__)N)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$	