File: _warning.py

package info (click to toggle)
python-skbio 0.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 9,312 kB
  • sloc: python: 60,482; ansic: 672; makefile: 224
file content (61 lines) | stat: -rw-r--r-- 1,955 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# ----------------------------------------------------------------------------
# Copyright (c) 2013--, scikit-bio development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE.txt, distributed with this software.
# ----------------------------------------------------------------------------

from warnings import warn, simplefilter


class SkbioWarning(Warning):
    """Filter our warnings from warnings given by 3rd parties."""

    pass


class EfficiencyWarning(SkbioWarning):
    """Warn about potentially accidental use of inefficient code.

    For example, if a user doesn't have an optimized version of a
    function/algorithm available in their scikit-bio installation, a slower,
    pure-Python implementation may be used instead. This warning can be used to
    let the user know they are using a version of the function that could be
    potentially orders of magnitude slower.

    """

    pass


class RepresentationWarning(SkbioWarning):
    """Warn about assumptions made for the successful completion of a process.

    Warn about substitutions, assumptions, or particular alterations that were
    made for the successful completion of a process. For example, if a value
    that is required for a task is not present, a best guess or least
    deleterious value could be used, accompanied by this warning.

    """

    pass


class DeprecationWarning(DeprecationWarning, SkbioWarning):
    """Used to indicate deprecated functionality in scikit-bio."""

    pass


def _warn_deprecated(func, ver, msg=None):
    """Warn of deprecated status."""
    if not hasattr(func, "warned"):
        simplefilter("once", DeprecationWarning)
        if msg:
            warn(
                f"{func.__name__} is deprecated as of {ver}. {msg}", DeprecationWarning
            )
        else:
            warn(f"{func.__name__} is deprecated as of {ver}.")
        func.warned = True