o
    ci                     @   s   d dl Z d dlZd dlmZmZ d dlmZ d dlmZ e	e
ZdZ	dddddedee d	ee d
eeeef  ddf
ddZddddddZdS )    N)OptionalUnion)log_once)_mark_annotated)helperroroldnewr   r   returnc                C   sf   d | |r
d |n|rd| nd}|r(t|ts$t|tr$||t|td| d  dS )ay  Warns (via the `logger` object) or throws a deprecation warning/error.

    Args:
        old: A description of the "thing" that is to be deprecated.
        new: A description of the new "thing" that replaces it.
        help: An optional help text to tell the user, what to
            do instead of using `old`.
        error: Whether or which exception to raise. If True, raise ValueError.
            If False, just warn. If `error` is-a subclass of Exception,
            raise that Exception.

    Raises:
        ValueError: If `error=True`.
        Exception: Of type `error`, iff `error` is a sub-class of `Exception`.
    z`{}` has been deprecated.{}z Use `{}` instead.  zDeprecationWarning: z( This will raise an error in the future!N)format
isinstancebool
issubclass	Exception
ValueErrorloggerwarning)r	   r
   r   r   msg r   O/home/ubuntu/.local/lib/python3.10/site-packages/ray/rllib/utils/deprecation.pydeprecation_warning   s    
r   )r
   r   c                   s    fdd}|S )a  Decorator for documenting a deprecated class, method, or function.

    Automatically adds a `deprecation.deprecation_warning(old=...,
    error=False)` to not break existing code at this point to the decorated
    class' constructor, method, or function.

    In a next major release, this warning should then be made an error
    (by setting error=True), which means at this point that the
    class/method/function is no longer supported, but will still inform
    the user about the deprecation event.

    In a further major release, the class, method, function should be erased
    entirely from the codebase.


    .. testcode::
        :skipif: True

        from ray.rllib.utils.deprecation import Deprecated
        # Deprecated class: Patches the constructor to warn if the class is
        # used.
        @Deprecated(new="NewAndMuchCoolerClass", error=False)
        class OldAndUncoolClass:
            ...

        # Deprecated class method: Patches the method to warn if called.
        class StillCoolClass:
            ...
            @Deprecated(new="StillCoolClass.new_and_much_cooler_method()",
                        error=False)
            def old_and_uncool_method(self, uncool_arg):
                ...

        # Deprecated function: Patches the function to warn if called.
        @Deprecated(new="new_and_much_cooler_function", error=False)
        def old_and_uncool_function(*uncool_args):
            ...
    c                    sP   t  r j fdd}| _t   S  fdd}|S )Nc                     s2   t pjrtpj d | i |S N)r	   r
   r   r   r   __name__r   argskwargs)r   r   r
   objobj_initr	   r   r   patched_inite   s   z0Deprecated.<locals>._inner.<locals>.patched_initc                     s2   t pjrtpj d | i |S r   r   r   )r   r   r
   r    r	   r   r   _ctorw   s   z)Deprecated.<locals>._inner.<locals>._ctor)inspectisclass__init__r   )r    r"   r#   r   r   r
   r	   )r    r!   r   _inner_   s   

zDeprecated.<locals>._innerr   )r	   r
   r   r   r(   r   r'   r   
Deprecated7   s   ('r)   )N)r$   loggingtypingr   r   ray.utilr   ray.util.annotationsr   	getLoggerr   r   DEPRECATED_VALUEstrr   r   r   r)   r   r   r   r   <module>   s.    

'