comparison env/lib/python3.9/site-packages/boltons/deprutils.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 # -*- coding: utf-8 -*-
2
3 """
4 Note that DeprecationWarnings are ignored by default in Python
5 2.7/3.2+, so be sure to either un-ignore them in your code, or run
6 Python with the -Wd flag.
7 """
8
9 import sys
10 from warnings import warn
11
12 ModuleType = type(sys)
13
14 # todo: only warn once
15
16
17 class DeprecatableModule(ModuleType):
18 def __init__(self, module):
19 name = module.__name__
20 super(DeprecatableModule, self).__init__(name=name)
21 self.__dict__.update(module.__dict__)
22
23 def __getattribute__(self, name):
24 get_attribute = super(DeprecatableModule, self).__getattribute__
25 try:
26 depros = get_attribute('_deprecated_members')
27 except AttributeError:
28 self._deprecated_members = depros = {}
29 ret = get_attribute(name)
30 message = depros.get(name)
31 if message is not None:
32 warn(message, DeprecationWarning, stacklevel=2)
33 return ret
34
35
36 def deprecate_module_member(mod_name, name, message):
37 module = sys.modules[mod_name]
38 if not isinstance(module, DeprecatableModule):
39 sys.modules[mod_name] = module = DeprecatableModule(module)
40 module._deprecated_members[name] = message
41 return