Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/boltons/deprutils.py @ 5:9b1c78e6ba9c draft default tip
"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
author | shellac |
---|---|
date | Mon, 01 Jun 2020 08:59:25 -0400 |
parents | 79f47841a781 |
children |
comparison
equal
deleted
inserted
replaced
4:79f47841a781 | 5:9b1c78e6ba9c |
---|---|
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 |