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
|
|||
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 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.