B
    	\                 @   sL   d dl Z d dlZd dlZddgZG dd deZdd ZG dd deZdS )    N
deprecatedDeprecationDictc               @   s:   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdS )r   a  Decorator to mark a function or class as deprecated.

    Issue a warning when the function is called/the class is instantiated and
    adds a warning to the docstring.

    The optional extra argument will be appended to the deprecation message
    and the docstring. Note: to use this with the default value for extra, put
    in an empty of parentheses:

    >>> from sklearn.utils import deprecated
    >>> deprecated() # doctest: +ELLIPSIS
    <sklearn.utils.deprecation.deprecated object at ...>

    >>> @deprecated()
    ... def some_function(): pass

    Parameters
    ----------
    extra : string
          to be added to the deprecation messages
     c             C   s
   || _ d S )N)extra)selfr    r   8lib/python3.7/site-packages/sklearn/utils/deprecation.py__init__"   s    zdeprecated.__init__c             C   s"   t |tr| |S | |S dS )zPCall method

        Parameters
        ----------
        obj : object
        N)
isinstancetype_decorate_class_decorate_fun)r   objr   r   r   __call__%   s    

zdeprecated.__call__c                sV   d|j  | jrd| j 7 |j  fdd}||_d|_ |  j|_ |_|S )NzClass %s is deprecatedz; %sc                 s   t jtd  | |S )N)category)warningswarnDeprecationWarning)argskwargs)initmsgr   r   wrapped9   s    z+deprecated._decorate_class.<locals>.wrappedr	   )__name__r   r	   _update_doc__doc__Zdeprecated_original)r   clsr   r   )r   r   r   r   1   s    
zdeprecated._decorate_classc                sN   d j  | jrd| j 7 t  fdd}| |j|_ |_|S )zDecorate function funzFunction %s is deprecatedz; %sc                 s   t jtd  | |S )N)r   )r   r   r   )r   r   )funr   r   r   r   K   s    z)deprecated._decorate_fun.<locals>.wrapped)r   r   	functoolswrapsr   r   __wrapped__)r   r   r   r   )r   r   r   r   D   s    
zdeprecated._decorate_func             C   s,   d}| j rd|| j f }|r(d||f }|S )NZ
DEPRECATEDz%s: %sz%s

%s)r   )r   ZolddocZnewdocr   r   r   r   W   s    zdeprecated._update_docN)r   )	r   
__module____qualname__r   r	   r   r   r   r   r   r   r   r   r      s   
c             C   sF   t jdk rtdt| dg }|dkr*g }dddd |D k}|S )	z=Helper to check if func is wraped by our deprecated decorator)      z-This is only available for python3.5 or above__closure__Nr   r   c             S   s   g | ]}t |jtr|jqS r   )r
   cell_contentsstr).0cr   r   r   
<listcomp>h   s   z"_is_deprecated.<locals>.<listcomp>)sysversion_infoNotImplementedErrorgetattrjoin)funcZclosuresZis_deprecatedr   r   r   _is_deprecated`   s    
r1   c                   s>   e Zd ZdZ fddZ fddZdddZd	d
 Z  ZS )r   zA dict which raises a warning when some keys are looked up

    Note, this does not raise a warning for __contains__ and iteration.

    It also will raise a warning even after the key has been manually set by
    the user.
    c                s   i | _ tt| j|| d S )N)_deprecationssuperr   r	   )r   r   r   )	__class__r   r   r	   v   s    zDeprecationDict.__init__c                s4   || j kr$| j | \}}tj|| tt| |S )N)r2   r   r   r3   r   __getitem__)r   keyZ	warn_argsZwarn_kwargs)r4   r   r   r5   z   s    
zDeprecationDict.__getitem__Nc             C   s"   y| | S  t k
r   |S X dS )zReturn the value corresponding to key, else default.

        Parameters
        ----------
        key : any hashable object
            The key
        default : object, optional
            The default returned when key is not in dict
        N)KeyError)r   r6   defaultr   r   r   get   s    zDeprecationDict.getc             O   s   ||f| j |< dS )zAdd a warning to be triggered when the specified key is read

        Parameters
        ----------
        key : any hashable object
            The key
        N)r2   )r   r6   r   r   r   r   r   add_warning   s    zDeprecationDict.add_warning)N)	r   r!   r"   r   r	   r5   r9   r:   __classcell__r   r   )r4   r   r   n   s
   
)	r+   r   r   __all__objectr   r1   dictr   r   r   r   r   <module>   s   X