backport()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
dl 0
loc 21
rs 9.376
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A deprecated_function() 0 5 1
1
"""
2
    Used internally to handle style changes without breaking backwards
3
    compatibility.
4
"""
5
6
import warnings as _warnings
7
import functools as _functools
8
9
def backport(func):
10
    """
11
        Backport a function name into an old style for compatibility.
12
13
        The docstring is updated to reflect that the new function returned is
14
        deprecated and that the other function is preferred.
15
        A DeprecationWarning is also raised for using this function.
16
17
        If the script is run with an optimization flag then the real function
18
        will be returned without being wrapped.
19
    """
20
    if not __debug__:
21
        return func
22
23
    @_functools.wraps(func)
24
    def deprecated_function(*args, **kargs):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
25
        _warnings.warn('This function name is deprecated',
26
                       DeprecationWarning, 2)
27
        return func(*args, **kargs)
28
    deprecated_function.__doc__ = None
29
    return deprecated_function
30
31
__all__ = []
32