diff --git a/pylint/checkers/base/__init__.py b/pylint/checkers/base/__init__.py index bf0be85664..92e8a9ce35 100644 --- a/pylint/checkers/base/__init__.py +++ b/pylint/checkers/base/__init__.py @@ -17,6 +17,7 @@ from pylint.checkers import utils from pylint.checkers.base.basic_checker import _BasicChecker from pylint.checkers.base.comparison_checker import ComparisonChecker +from pylint.checkers.base.pass_checker import PassChecker from pylint.checkers.utils import ( infer_all, is_overload_stub, @@ -2311,26 +2312,6 @@ def _check_docstring( ) -class PassChecker(_BasicChecker): - """Check if the pass statement is really necessary.""" - - msgs = { - "W0107": ( - "Unnecessary pass statement", - "unnecessary-pass", - 'Used when a "pass" statement that can be avoided is encountered.', - ) - } - - @utils.check_messages("unnecessary-pass") - def visit_pass(self, node: nodes.Pass) -> None: - if len(node.parent.child_sequence(node)) > 1 or ( - isinstance(node.parent, (nodes.ClassDef, nodes.FunctionDef)) - and node.parent.doc_node - ): - self.add_message("unnecessary-pass", node=node) - - def _infer_dunder_doc_attribute(node): # Try to see if we have a `__doc__` attribute. try: diff --git a/pylint/checkers/base/pass_checker.py b/pylint/checkers/base/pass_checker.py new file mode 100644 index 0000000000..26b915bc45 --- /dev/null +++ b/pylint/checkers/base/pass_checker.py @@ -0,0 +1,28 @@ +# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html +# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt + +from astroid import nodes + +from pylint.checkers import utils +from pylint.checkers.base.basic_checker import _BasicChecker + + +class PassChecker(_BasicChecker): + """Check if the pass statement is really necessary.""" + + msgs = { + "W0107": ( + "Unnecessary pass statement", + "unnecessary-pass", + 'Used when a "pass" statement that can be avoided is encountered.', + ) + } + + @utils.check_messages("unnecessary-pass") + def visit_pass(self, node: nodes.Pass) -> None: + if len(node.parent.child_sequence(node)) > 1 or ( + isinstance(node.parent, (nodes.ClassDef, nodes.FunctionDef)) + and node.parent.doc_node + ): + self.add_message("unnecessary-pass", node=node)