summaryrefslogtreecommitdiff
path: root/pylint/checkers/deprecated.py
diff options
context:
space:
mode:
Diffstat (limited to 'pylint/checkers/deprecated.py')
-rw-r--r--pylint/checkers/deprecated.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/pylint/checkers/deprecated.py b/pylint/checkers/deprecated.py
index 9a4f636e4..8aaa02506 100644
--- a/pylint/checkers/deprecated.py
+++ b/pylint/checkers/deprecated.py
@@ -32,6 +32,11 @@ class DeprecatedMixin:
"deprecated-argument",
"The argument is marked as deprecated and will be removed in the future.",
),
+ "W0402": (
+ "Uses of a deprecated module %r",
+ "deprecated-module",
+ "A module marked as deprecated is imported.",
+ ),
}
@utils.check_messages(
@@ -47,6 +52,18 @@ class DeprecatedMixin:
except astroid.InferenceError:
pass
+ @utils.check_messages("deprecated-module")
+ def visit_import(self, node):
+ """triggered when an import statement is seen"""
+ for name in (name for name, _ in node.names):
+ self.check_deprecated_module(node, name)
+
+ @utils.check_messages("deprecated-module")
+ def visit_importfrom(self, node):
+ """triggered when a from statement is seen"""
+ basename = node.modname
+ self.check_deprecated_module(node, basename)
+
def deprecated_methods(self) -> Container[str]:
"""Callback returning the deprecated methods/functions.
@@ -85,6 +102,22 @@ class DeprecatedMixin:
# pylint: disable=unused-argument
return ()
+ def deprecated_modules(self) -> Iterable:
+ """Callback returning the deprecated modules.
+
+ Returns:
+ collections.abc.Container of deprecated module names.
+ """
+ # pylint: disable=no-self-use
+ return ()
+
+ def check_deprecated_module(self, node, mod_path):
+ """Checks if the module is deprecated"""
+
+ for mod_name in self.deprecated_modules():
+ if mod_path == mod_name or mod_path.startswith(mod_name + "."):
+ self.add_message("deprecated-module", node=node, args=mod_path)
+
def check_deprecated_method(self, node, inferred):
"""Executes the checker for the given node. This method should
be called from the checker implementing this mixin.