Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/openpyxl/compat/__init__.py: 78%
27 statements
« prev ^ index » next coverage.py v7.3.3, created at 2023-12-20 06:34 +0000
« prev ^ index » next coverage.py v7.3.3, created at 2023-12-20 06:34 +0000
1# Copyright (c) 2010-2023 openpyxl
3from .numbers import NUMERIC_TYPES
4from .strings import safe_string
6import warnings
7from functools import wraps
8import inspect
11class DummyCode:
13 pass
16# from https://github.com/tantale/deprecated/blob/master/deprecated/__init__.py
17# with an enhancement to update docstrings of deprecated functions
18string_types = (type(b''), type(u''))
19def deprecated(reason):
21 if isinstance(reason, string_types):
23 def decorator(func1):
25 if inspect.isclass(func1):
26 fmt1 = "Call to deprecated class {name} ({reason})."
27 else:
28 fmt1 = "Call to deprecated function {name} ({reason})."
30 @wraps(func1)
31 def new_func1(*args, **kwargs):
32 #warnings.simplefilter('default', DeprecationWarning)
33 warnings.warn(
34 fmt1.format(name=func1.__name__, reason=reason),
35 category=DeprecationWarning,
36 stacklevel=2
37 )
38 return func1(*args, **kwargs)
40 # Enhance docstring with a deprecation note
41 deprecationNote = "\n\n.. note::\n Deprecated: " + reason
42 if new_func1.__doc__:
43 new_func1.__doc__ += deprecationNote
44 else:
45 new_func1.__doc__ = deprecationNote
46 return new_func1
48 return decorator
50 elif inspect.isclass(reason) or inspect.isfunction(reason):
51 raise TypeError("Reason for deprecation must be supplied")
53 else:
54 raise TypeError(repr(type(reason)))