Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/boltons/deprutils.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author | shellac |
---|---|
date | Sat, 02 May 2020 07:14:21 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:26e78fe6e8c4 |
---|---|
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 |