o
    EDi6                     @   s\   d Z ddlZddlZddlZzddlZW n ey!   ddlZY nw G dd deZeZ	dS )a  
Parameters deprecation
======================

.. _Tantale's Blog: https://tantale.github.io/
.. _Deprecated Parameters: https://tantale.github.io/articles/deprecated_params/

This module introduces a :class:`deprecated_params` decorator to specify that one (or more)
parameter(s) are deprecated: when the user executes a function with a deprecated parameter,
he will see a warning message in the console.

The decorator is customizable, the user can specify the deprecated parameter names
and associate to each of them a message providing the reason of the deprecation.
As with the :func:`~deprecated.classic.deprecated` decorator, the user can specify
a version number (using the *version* parameter) and also define the warning message category
(a subclass of :class:`Warning`) and when to display the messages (using the *action* parameter).

The complete study concerning the implementation of this decorator is available on the `Tantale's blog`_,
on the `Deprecated Parameters`_ page.
    Nc                   @   s@   e Zd ZdZdefddZdddZdd Zd	d
 Zdd Z	dS )DeprecatedParamszg
    Decorator used to decorate a function which at least one
    of the parameters is deprecated.
     c                 C   s   i | _ || _| j||d d S )N)reason)messagescategorypopulate_messages)selfparamr   r    r
   J/var/www/Datamplify/venv/lib/python3.10/site-packages/deprecated/params.py__init__'   s   zDeprecatedParams.__init__c                 C   sN   t |tr| j| d S t |tr#d}|p|j|d}|| j|< d S t|)Nz!'{param}' parameter is deprecated)r	   )
isinstancedictr   updatestrformat	TypeError)r   r	   r   fmtr
   r
   r   r   ,   s   

z"DeprecatedParams.populate_messagesc                    s8   |j |i |}tj|jfi |j} fdd|D S )Nc                    s   g | ]	}| j v r|qS r
   r   .0r	   r   r
   r   
<listcomp>9   s    z1DeprecatedParams.check_params.<locals>.<listcomp>)bindcollectionsOrderedDict	argumentskwargs)r   	signatureargsr   bindingboundr
   r   r   check_params6   s   zDeprecatedParams.check_paramsc                 C   s    |D ]}t j|| jdd qd S )N   )r   
stacklevel)warningswarnr   )r   r   messager
   r
   r   warn_messages;   s   zDeprecatedParams.warn_messagesc                    s(   t  t  fdd}|S )Nc                     s>   j g| R i |}fdd|D   | i |S )Nc                    s   g | ]} j | qS r
   r   r   r   r
   r   r   G   s    z>DeprecatedParams.__call__.<locals>.wrapper.<locals>.<listcomp>)r"   r(   )r   r   invalid_paramsfr   r   r
   r   wrapperD   s   z*DeprecatedParams.__call__.<locals>.wrapper)inspectr   	functoolswraps)r   r+   r,   r
   r*   r   __call__@   s   
zDeprecatedParams.__call__N)r   )
__name__
__module____qualname____doc__DeprecationWarningr   r   r"   r(   r0   r
   r
   r
   r   r   !   s    

r   )
r4   r   r.   r%   inspect2r-   ImportErrorobjectr   deprecated_paramsr
   r
   r
   r   <module>   s   .