mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 18:27:59 -05:00
[Core] Add deprecation warnings about removal of shared libraries. (#3106)
* feat: add deprecation warning when importing shared libs * enhance(downloader): add shared libs deprecation warns * enhance: add deprecation warning when (re)loading cogs * docs(downloader): add deprecation note about shared libs * chore(changelog): add towncrier entries * style: split long tuple unpacks in multiple lines * fix: argument to `humanize_list` has to be a sequence
This commit is contained in:
29
redbot/core/_sharedlibdeprecation.py
Normal file
29
redbot/core/_sharedlibdeprecation.py
Normal file
@@ -0,0 +1,29 @@
|
||||
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 Red 3.3.\n"
|
||||
"You should inform author of the cog about this message."
|
||||
)
|
||||
warnings.warn(msg, SharedLibDeprecationWarning, stacklevel=2)
|
||||
return None
|
||||
Reference in New Issue
Block a user