o
    b                     @   s   d Z ddlmZ ddlmZ ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 dd	l
mZ dd
lmZ ddlmZ dZG dd dejZdddZdddZdd Zdd ZeeddZeejee eejeee dS )z9Astroid hooks for understanding functools library module.    )partial)chainN)	arguments)BoundMethod)extract_node)helpers)objectmodel)MANAGER)objectszfunctools.lru_cachec                   @   s4   e Zd ZdZedd Zedd Zedd ZdS )	LruWrappedModelzSpecial attribute model for functions decorated with functools.lru_cache.

    The said decorators patches at decoration time some functions onto
    the decorated function.
    c                 C   s   | j S N)	_instance)self r   \/var/www/secure340b-portal/env/lib/python3.10/site-packages/astroid/brain/brain_functools.pyattr___wrapped__   s   z LruWrappedModel.attr___wrapped__c                    s,   t d G  fdddt}|| j| jdS )NzQ
        from functools import _CacheInfo
        _CacheInfo(0, 0, 0, 0)
        c                       s   e Zd Zd fdd	ZdS )z=LruWrappedModel.attr_cache_info.<locals>.CacheInfoBoundMethodNc                 3   s    t  V  d S r   )r   Z
safe_infer)r   Zcallercontext
cache_infor   r   infer_call_result*   s   zOLruWrappedModel.attr_cache_info.<locals>.CacheInfoBoundMethod.infer_call_resultr   )__name__
__module____qualname__r   r   r   r   r   CacheInfoBoundMethod)   s    r   proxybound)r   r   r   )r   r   r   r   r   attr_cache_info    s
   zLruWrappedModel.attr_cache_infoc                 C   s   t d}t|| jj dS )Nzdef cache_clear(self): passr   )r   r   r   parentscope)r   noder   r   r   attr_cache_clear/   s   z LruWrappedModel.attr_cache_clearN)r   r   r   __doc__propertyr   r   r!   r   r   r   r   r      s    

r   c                 C   s   t  | | _d S r   )r   Zspecial_attributes)r    r   r   r   r   _transform_lru_cache5   s   r$   c           	   
   C   s<  t j| }t|j}|dk rtd|dkr |js td|jd }z
t|j	|d}W n tj
y@ } ztj|d }~ww |tju rKtdt|tjsVtdt|jjp\d|jjpad}td	d
 |D }t|j| rxtdtj||j|j|j|j|jd}|j|j|j|j|j|j|jd t|fS )N   z-functools.partial takes at least one argumentz>functools.partial needs at least to have some filled argumentsr   )r   z!Cannot infer the wrapped functionz&The wrapped function is not a functionr   c                 s   s"    | ]}t |tjr|jV  qd S r   )
isinstanceastroidZ
AssignNamename).0paramr   r   r   	<genexpr>\   s    

z/_functools_partial_inference.<locals>.<genexpr>z,wrapped function received unknown parameters)r(   doclineno
col_offsetr   )argsbody
decoratorsreturnstype_comment_returnstype_comment_args) r   ZCallSiteZ	from_calllenZpositional_argumentsr'   ZUseInferenceDefaultZkeyword_argumentsnextZinferZInferenceErrorZUninferabler&   FunctionDefr   r/   
kwonlyargssetr
   ZPartialFunctionr(   r,   r-   r.   r   Zpostinitr0   r1   r2   r3   r4   iter)	r    r   callZnumber_of_positionalZpartial_functionZinferred_wrapped_functionexcZfunction_parametersZparameter_namesr   r   r   _functools_partial_inference@   sb   







r=   c                 C   s:   | j sdS | j jD ]}t|tjsq	t|dr dS q	dS )z=Check if the given function node is decorated with lru_cache.F	lru_cacheT)r1   nodesr&   r'   Call_looks_like_functools_member)r    	decoratorr   r   r   _looks_like_lru_cachey   s   
rC   c                 C   sV   t | jtjr| jj|kS t | jtjr)| jj|ko(t | jjtjo(| jjjdkS dS )z8Check if the given Call node is a functools.partial call	functoolsN)r&   funcr'   Namer(   	Attributeattrnameexpr)r    memberr   r   r   rA      s   rA   r   )rJ   r   )r"   rD   r   	itertoolsr   r'   r   r   r   r   Zastroid.interpreterr   r	   r
   Z	LRU_CACHEZFunctionModelr   r$   r=   rC   rA   Z_looks_like_partialZregister_transformr7   r@   Zinference_tipr   r   r   r   <module>   s4   
 
9