
import functools
import inspect
import warnings

string_types = (type(b''), type(u''))


def deprecated(reason):
    """
    This is a decorator which can be used to mark functions
    as deprecated. It will result in a warning being emitted
    when the function is used.
    """

    if isinstance(reason, string_types):

        # The @deprecated is used with a 'reason'.
        #
        # .. code-block:: python
        #
        #    @deprecated("please, use another function")
        #    def old_function(x, y):
        #      pass

        def decorator(func1):

            if inspect.isclass(func1):
                fmt1 = "Call to deprecated class {name} ({reason})."
            else:
                fmt1 = "Call to deprecated function {name} ({reason})."

            @functools.wraps(func1)
            def new_func1(*args, **kwargs):
                warnings.simplefilter('always', DeprecationWarning)
                warnings.warn(
                    fmt1.format(name=func1.__name__, reason=reason),
                    category=DeprecationWarning,
                    stacklevel=2
                )
                warnings.simplefilter('default', DeprecationWarning)
                return func1(*args, **kwargs)

            return new_func1

        return decorator

    elif inspect.isclass(reason) or inspect.isfunction(reason):

        # The @deprecated is used without any 'reason'.
        #
        # .. code-block:: python
        #
        #    @deprecated
        #    def old_function(x, y):
        #      pass

        func2 = reason

        if inspect.isclass(func2):
            fmt2 = "Call to deprecated class {name}."
        else:
            fmt2 = "Call to deprecated function {name}."

        @functools.wraps(func2)
        def new_func2(*args, **kwargs):
            warnings.simplefilter('always', DeprecationWarning)
            warnings.warn(
                fmt2.format(name=func2.__name__),
                category=DeprecationWarning,
                stacklevel=2
            )
            warnings.simplefilter('default', DeprecationWarning)
            return func2(*args, **kwargs)

        return new_func2

    else:
        raise TypeError(repr(type(reason)))


import functools
import warnings


def deprecated(func):
    """
    This is a decorator which can be used to mark functions
    as deprecated. It will result in a warning being emmitted
    when the function is used.
    """

    @functools.wraps(func)
    def new_func(*args, **kwargs):
        warnings.simplefilter('always', DeprecationWarning)
        warnings.warn(
            "Call to deprecated function {0}.".format(func.__name__),
            category=DeprecationWarning,
            stacklevel=2
        )
        warnings.simplefilter('default', DeprecationWarning)
        return func(*args, **kwargs)

    return new_func

Replace invalid string format '{}' by '{0}' for Python 2.6 compatibility.
Replace invalid string format '{}' by '{0}' for Python 2.6 compatibility.

  
  import functools
- import inspect
  import warnings
  
- string_types = (type(b''), type(u''))
  
- 
- def deprecated(reason):
+ def deprecated(func):
      """
      This is a decorator which can be used to mark functions
-     as deprecated. It will result in a warning being emitted
+     as deprecated. It will result in a warning being emmitted
      when the function is used.
      """
  
-     if isinstance(reason, string_types):
+     @functools.wraps(func)
+     def new_func(*args, **kwargs):
+         warnings.simplefilter('always', DeprecationWarning)
+         warnings.warn(
+             "Call to deprecated function {0}.".format(func.__name__),
+             category=DeprecationWarning,
+             stacklevel=2
+         )
+         warnings.simplefilter('default', DeprecationWarning)
+         return func(*args, **kwargs)
  
+     return new_func
-         # The @deprecated is used with a 'reason'.
-         #
-         # .. code-block:: python
-         #
-         #    @deprecated("please, use another function")
-         #    def old_function(x, y):
-         #      pass
  
-         def decorator(func1):
- 
-             if inspect.isclass(func1):
-                 fmt1 = "Call to deprecated class {name} ({reason})."
-             else:
-                 fmt1 = "Call to deprecated function {name} ({reason})."
- 
-             @functools.wraps(func1)
-             def new_func1(*args, **kwargs):
-                 warnings.simplefilter('always', DeprecationWarning)
-                 warnings.warn(
-                     fmt1.format(name=func1.__name__, reason=reason),
-                     category=DeprecationWarning,
-                     stacklevel=2
-                 )
-                 warnings.simplefilter('default', DeprecationWarning)
-                 return func1(*args, **kwargs)
- 
-             return new_func1
- 
-         return decorator
- 
-     elif inspect.isclass(reason) or inspect.isfunction(reason):
- 
-         # The @deprecated is used without any 'reason'.
-         #
-         # .. code-block:: python
-         #
-         #    @deprecated
-         #    def old_function(x, y):
-         #      pass
- 
-         func2 = reason
- 
-         if inspect.isclass(func2):
-             fmt2 = "Call to deprecated class {name}."
-         else:
-             fmt2 = "Call to deprecated function {name}."
- 
-         @functools.wraps(func2)
-         def new_func2(*args, **kwargs):
-             warnings.simplefilter('always', DeprecationWarning)
-             warnings.warn(
-                 fmt2.format(name=func2.__name__),
-                 category=DeprecationWarning,
-                 stacklevel=2
-             )
-             warnings.simplefilter('default', DeprecationWarning)
-             return func2(*args, **kwargs)
- 
-         return new_func2
- 
-     else:
-         raise TypeError(repr(type(reason)))
- 
Replace invalid string format '{}' by '{0}' for Python 2.6 compatibility.
## Code Before:

import functools
import inspect
import warnings

string_types = (type(b''), type(u''))


def deprecated(reason):
    """
    This is a decorator which can be used to mark functions
    as deprecated. It will result in a warning being emitted
    when the function is used.
    """

    if isinstance(reason, string_types):

        # The @deprecated is used with a 'reason'.
        #
        # .. code-block:: python
        #
        #    @deprecated("please, use another function")
        #    def old_function(x, y):
        #      pass

        def decorator(func1):

            if inspect.isclass(func1):
                fmt1 = "Call to deprecated class {name} ({reason})."
            else:
                fmt1 = "Call to deprecated function {name} ({reason})."

            @functools.wraps(func1)
            def new_func1(*args, **kwargs):
                warnings.simplefilter('always', DeprecationWarning)
                warnings.warn(
                    fmt1.format(name=func1.__name__, reason=reason),
                    category=DeprecationWarning,
                    stacklevel=2
                )
                warnings.simplefilter('default', DeprecationWarning)
                return func1(*args, **kwargs)

            return new_func1

        return decorator

    elif inspect.isclass(reason) or inspect.isfunction(reason):

        # The @deprecated is used without any 'reason'.
        #
        # .. code-block:: python
        #
        #    @deprecated
        #    def old_function(x, y):
        #      pass

        func2 = reason

        if inspect.isclass(func2):
            fmt2 = "Call to deprecated class {name}."
        else:
            fmt2 = "Call to deprecated function {name}."

        @functools.wraps(func2)
        def new_func2(*args, **kwargs):
            warnings.simplefilter('always', DeprecationWarning)
            warnings.warn(
                fmt2.format(name=func2.__name__),
                category=DeprecationWarning,
                stacklevel=2
            )
            warnings.simplefilter('default', DeprecationWarning)
            return func2(*args, **kwargs)

        return new_func2

    else:
        raise TypeError(repr(type(reason)))

## Instruction:
Replace invalid string format '{}' by '{0}' for Python 2.6 compatibility.
## Code After:

import functools
import warnings


def deprecated(func):
    """
    This is a decorator which can be used to mark functions
    as deprecated. It will result in a warning being emmitted
    when the function is used.
    """

    @functools.wraps(func)
    def new_func(*args, **kwargs):
        warnings.simplefilter('always', DeprecationWarning)
        warnings.warn(
            "Call to deprecated function {0}.".format(func.__name__),
            category=DeprecationWarning,
            stacklevel=2
        )
        warnings.simplefilter('default', DeprecationWarning)
        return func(*args, **kwargs)

    return new_func
