
    e                    R   d 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
mZmZmZmZ ddlmZ ddlmZm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"m#Z# ddl$m%Z%m&Z& dZ' G d dejP                        Z)dddZ*	 d	 	 	 	 	 ddZ+ddZ,ddZ- ee-d      Z.d dZ/y)!z9Astroid hooks for understanding functools library module.    )annotations)Iterator)partial)chain)BoundMethod	argumentsextract_nodenodesobjects)InferenceContext)InferenceErrorUseInferenceDefault)inference_tip)objectmodel)AstroidManager)
AssignName	AttributeCallName)FunctionDef)InferenceResultSuccessfulInferenceResult)UninferableBase
safe_inferzfunctools.lru_cachec                  @    e Zd ZdZed        Zed        Zed        Zy)LruWrappedModelzSpecial attribute model for functions decorated with functools.lru_cache.

    The said decorators patches at decoration time some functions onto
    the decorated function.
    c                    | j                   S N)	_instance)selfs    ?/usr/lib/python3/dist-packages/astroid/brain/brain_functools.pyattr___wrapped__z LruWrappedModel.attr___wrapped__"   s    ~~    c                x    t        d       G fddt              } || j                  | j                        S )NzQ
        from functools import _CacheInfo
        _CacheInfo(0, 0, 0, 0)
        c                  (    e Zd Z	 d	 	 	 	 	 d fdZy)=LruWrappedModel.attr_cache_info.<locals>.CacheInfoBoundMethodNc              3  4   K   t              }|J | y wr   )r   )r    callercontextres
cache_infos       r!   infer_call_resultzOLruWrappedModel.attr_cache_info.<locals>.CacheInfoBoundMethod.infer_call_result0   s"     
 !,&	s   r   )r(   z SuccessfulInferenceResult | Noner)   InferenceContext | NonereturnzIterator[InferenceResult])__name__
__module____qualname__r,   )r+   s   r!   CacheInfoBoundMethodr&   /   s)     488 1 +	r#   r2   proxybound)r	   r   r   )r    r2   r+   s     @r!   attr_cache_infozLruWrappedModel.attr_cache_info&   s5    !

	; 	 $$..OOr#   c                v    t        d      }t        || j                  j                  j	                               S )Nzdef cache_clear(self): passr3   )r	   r   r   parentscope)r    nodes     r!   attr_cache_clearz LruWrappedModel.attr_cache_clear;   s-    =>T^^-B-B-H-H-JKKr#   N)r/   r0   r1   __doc__propertyr"   r6   r;    r#   r!   r   r      sG       P P( L Lr#   r   Nc                .     t               |       | _        y r   )r   special_attributes)r:   r)   s     r!   _transform_lru_cacherA   A   s     0o/5Dr#   c           	        t         j                  j                  | |      }t        |j                        }|dk  rt        d      |dk(  r|j                  st        d      |j                  d   }	 t        |j                  |            }t        |t              rt        d      t        |t              st        d      |j                  sg }nUt        |j                  j                  xs d|j                  j                   xs d|j                  j"                  xs d      }|D ch c]  }t        |t$              s|j&                  ! }	}t)        |j                        |	z
  rt        d	      t+        j,                  ||j&                  |j.                  |j0                  | j2                  
      }|j5                  |j                  |j6                  |j8                  |j:                  |j<                  |j>                  |j@                         tC        |f      S # t        t        f$ r}t
        |d }~ww xY wc c}w )N)r)      z-functools.partial takes at least one argumentz>functools.partial needs at least to have some filled argumentsr   z!Cannot infer the wrapped functionz&The wrapped function is not a functionr>   z,wrapped function received unknown parameters)namelineno
col_offsetr8   )argsbody
decoratorsreturnstype_comment_returnstype_comment_argsdoc_node)"r   CallSite	from_calllenpositional_argumentsr   keyword_argumentsnextinferr   StopIteration
isinstancer   r   rG   r   posonlyargs
kwonlyargsr   rD   setr   PartialFunctionrE   rF   r8   postinitrH   rI   rJ   rK   rL   rM   iter)
r:   r)   callnumber_of_positionalpartial_functioninferred_wrapped_functionexcfunction_parametersparamparameter_namess
             r!   _functools_partial_inferencere   K   s'    ''g'>Dt889a!"QRRq )?)?!L
 	
 003+$()9)?)?)?)P$Q! +_=!"EFF/=!"JKK %)) #%**//52%**66<"%**55;
 !4z%7T

O  4!!"_4!"PQQ..&++(//,77{{ &++&++,77)116KK3EE*33   !#$$O M* +!s*+"s$   3H! ,H?H?!H<0H77H<c                    | j                   sy| j                   j                  D ]'  }t        |t        t        f      st        |d      s' y y)z=Check if the given function node is decorated with lru_cache.F	lru_cacheT)rI   r
   rV   r   r   _looks_like_functools_member)r:   	decorators     r!   _looks_like_lru_cacherj      sI    ??__** 	)i%67'	;?	
 r#   c                   t        | t              r| j                  |k(  S t        | j                  t              r| j                  j
                  |k(  S t        | j                  t              rd| j                  j                  |k(  xrI t        | j                  j                  t              xr# | j                  j                  j
                  dk(  S y)z?Check if the given Call node is the wanted member of functools.	functoolsF)rV   r   attrnamefuncr   rD   expr)r:   members     r!   rh   rh      s    $	"}}&&$))T"yy~~''$))Y'II&( 3499>>403		##{2	

 r#   r   )rp   c                    | j                  t        t        t               | j                  t        t        t              t               y r   )register_transformr   rA   rj   r   r   re   _looks_like_partial)managers    r!   registerru      s3    {,@BWX23r#   r   )r)   r-   r.   None)r:   z
nodes.Callr)   r-   r.   z!Iterator[objects.PartialFunction])r.   bool)r:   zAttribute | Callrp   strr.   rw   )rt   r   r.   rv   )0r<   
__future__r   collections.abcr   rl   r   	itertoolsr   astroidr   r   r	   r
   r   astroid.contextr   astroid.exceptionsr   r   astroid.inference_tipr   astroid.interpreterr   astroid.managerr   astroid.nodes.node_classesr   r   r   r   astroid.nodes.scoped_nodesr   astroid.typingr   r   astroid.utilr   r   	LRU_CACHEFunctionModelr   rA   re   rj   rh   rs   ru   r>   r#   r!   <module>r      s   
 @ " $   H H , B / + * H H 2 E 4!	#Lk// #LL6 :>6%
6%66%&6%r	 :9M r#   