File: deprecation.py

package info (click to toggle)
python-pylxd 2.2.10-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 820 kB
  • sloc: python: 7,258; sh: 104; makefile: 21
file content (26 lines) | stat: -rw-r--r-- 786 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import warnings

warnings.simplefilter('once', DeprecationWarning)


class deprecated():  # pragma: no cover
    """A decorator for warning about deprecation warnings.

    The decorator takes an optional message argument. This message can
    be used to direct the user to a new API or specify when it will
    be removed.
    """

    DEFAULT_MESSAGE = '{} is deprecated and will be removed soon.'

    def __init__(self, message=None):
        self.message = message

    def __call__(self, f):
        def wrapped(*args, **kwargs):
            if self.message is None:
                self.message = self.DEFAULT_MESSAGE.format(
                    f.__name__)
            warnings.warn(self.message, DeprecationWarning)
            return f(*args, **kwargs)
        return wrapped