a
    lc_                     @   st   d Z ddlmZ ddlmZ e Ze ZeddfddZefddZ	efd	d
Z
dd ZG dd deZdd ZdS )z
- the popular ``_memoize_default`` works like a typical memoize and returns the
  default otherwise.
- ``CachedMetaClass`` uses ``_memoize_default`` to do the same with classes.
    wraps)debugFc                    s    fdd}|S )aO   This is a typical memoization decorator, BUT there is one difference:
    To prevent recursion it sets defaults.

    Preventing recursion is in this case the much bigger use than speed. I
    don't think, that there is a big speed difference, but there are many cases
    where recursion could happen (think about a = b; b = a).
    c                    s    fdd}|S )Nc                    s   r| j }nr|d j }n| jj }z| }W n tyN   i  |< }Y n0 | |t| f}||v rr|| S  tur ||< | g|R i |}|||< |S d S )Nr   )memoize_cacheinference_stateKeyError	frozensetitems_NO_DEFAULT)objargskwargscachememokeyrv)defaultfunctioninference_state_is_first_argsecond_arg_is_inference_state P/var/www/html/django/DPS/env/lib/python3.9/site-packages/jedi/inference/cache.pywrapper   s"    z/_memoize_default.<locals>.func.<locals>.wrapperr   r   r   r   r   r   r   r   func   s    z_memoize_default.<locals>.funcr   )r   r   r   r   r   r   r   _memoize_default   s    	r   c                    s    fdd}|S )Nc                    s   t  dd| S )NT)r   r   r   r   r   r   r   	decorator5   s    z1inference_state_function_cache.<locals>.decoratorr   r   r!   r   r    r   inference_state_function_cache4   s    r#   c                    s    fdd}|S )Nc                    s   t  d| S )Nr    r   r   r    r   r   r!   <   s    z/inference_state_method_cache.<locals>.decoratorr   r"   r   r    r   inference_state_method_cache;   s    r$   c                  C   s   dd } | S )Nc                 S   s   t dd| S )NT)r   r   )callr   r   r   r!   C   s    z8inference_state_as_method_param_cache.<locals>.decoratorr   )r!   r   r   r   %inference_state_as_method_param_cacheB   s    r&   c                       s&   e Zd ZdZe  fddZ  ZS )CachedMetaClassz
    This is basically almost the same than the decorator above, it just caches
    class initializations. Either you do it this way or with decorators, but
    with decorators you lose class access (isinstance, etc).
    c                    s   t  j|i |S )N)super__call__)selfr   r   	__class__r   r   r)   O   s    zCachedMetaClass.__call__)__name__
__module____qualname____doc__r&   r)   __classcell__r   r   r+   r   r'   I   s   r'   c                  C   s   dd } | S )z
    This is a special memoizer. It memoizes generators and also checks for
    recursion errors and returns no further iterator elemends in that case.
    c                    s   t   fdd}|S )Nc           
      ?   s  | j j}z|  }W n ty2   i  | < }Y n0 | |t| f}||v r\|| \}}n& | g|R i |}g }||f||< d}z(|| }	|	tu rtd|   W d S W nD ty   |	t t
|d }	|	d u r|  Y d S |	|d< Y n0 |	V  |d7 }qd S )Nr   z"Found a generator recursion for %s   )r   r   r   r   r	   _RECURSION_SENTINELr   warning
IndexErrorappendnextpop)
r   r   r   r   r   r   Zactual_generatorZ
cached_lstiZnext_elementr   r   r   r   Z   s4    


zEinference_state_method_generator_cache.<locals>.func.<locals>.wrapperr   r   r   r   r   r   Y   s    !z4inference_state_method_generator_cache.<locals>.funcr   r   r   r   r   &inference_state_method_generator_cacheT   s    %r;   N)r0   	functoolsr   Zjedir   objectr
   r4   r   r#   r$   r&   typer'   r;   r   r   r   r   <module>   s   
&