Red-DiscordBot/redbot/core/_sharedlibdeprecation.py
jack1142 b49b53934d
Update deprecation warnings (#3608)
* Make deprecation notice specify minor release based on soonest date

* Stop specifying a specific release in shared libs deprecation notice

* Add actual deprecation warning for `APIToken` (OMG, this is so cool)

* Add dates (2020-08-05 for all)

* address review

* improve consistency

* Add __dir__ and show APIToken in docs (or maybe I want to annoy Flame)

* fix module name when importing non-existent name from parent package

* Fix stack level used by depr warn in `redbot.core.commands`
2020-06-22 03:25:33 +02:00

30 lines
972 B
Python

from importlib.abc import MetaPathFinder
import warnings
class SharedLibDeprecationWarning(DeprecationWarning):
pass
warnings.simplefilter("always", SharedLibDeprecationWarning)
class SharedLibImportWarner(MetaPathFinder):
"""
Deprecation warner for shared libraries. This class sits on `sys.meta_path`
and prints warning if imported module is a shared library
"""
def find_spec(self, fullname, path, target=None) -> None:
"""This is only supposed to print warnings, it won't ever return module spec."""
parts = fullname.split(".")
if parts[0] != "cog_shared" or len(parts) != 2:
return None
msg = (
"One of cogs uses shared libraries which are"
" deprecated and scheduled for removal in the future.\n"
"You should inform author of the cog about this message."
)
warnings.warn(msg, SharedLibDeprecationWarning, stacklevel=2)
return None