B
    vdX                 @   s0   d dl Z d dlZdgZG dd dZdd ZdS )    N
deprecatedc               @   sB   e Zd ZdZdddZ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()
    <sklearn.utils.deprecation.deprecated object at ...>

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

    Parameters
    ----------
    extra : str, default=''
          To be added to the deprecation messages.
     c             C   s
   || _ d S )N)extra)selfr    r   f/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/sklearn/utils/deprecation.py__init__"   s    zdeprecated.__init__c             C   s6   t |tr| |S t |tr(| |S | |S dS )zPCall method

        Parameters
        ----------
        obj : object
        N)
isinstancetype_decorate_classproperty_decorate_property_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FutureWarning)argskwargs)initmsgr   r   wrappedB   s    z+deprecated._decorate_class.<locals>.wrappedr   )__name__r   r   _update_doc__doc__Zdeprecated_original)r   clsr   r   )r   r   r   r   :   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   U   s    z)deprecated._decorate_fun.<locals>.wrapped)r   r   	functoolswrapsr   r   __wrapped__)r   r   r   r   )r   r   r   r   N   s    
zdeprecated._decorate_func                s4   | j  tt fdd}| |j|_|S )Nc                 s   t j td j| |S )N)r   )r   r   r   fget)r   r   )r   propr   r   r   d   s    z.deprecated._decorate_property.<locals>.wrapped)r   r   r   r    r   r   )r   r#   r   r   )r   r#   r   r   a   s
    zdeprecated._decorate_propertyc             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   n   s    zdeprecated._update_docN)r   )
r   
__module____qualname__r   r   r   r   r   r   r   r   r   r   r   r      s   
c             C   s4   t | dg }|dkrg }dddd |D k}|S )z>Helper to check if func is wrapped by our deprecated decorator__closure__Nr   r   c             S   s   g | ]}t |jtr|jqS r   )r	   cell_contentsstr).0cr   r   r   
<listcomp>}   s    z"_is_deprecated.<locals>.<listcomp>)getattrjoin)funcZclosuresZis_deprecatedr   r   r   _is_deprecatedw   s    r/   )r   r   __all__r   r/   r   r   r   r   <module>   s   o