Skip to content

Commit

Permalink
[refactor] Create a file for the PassChecker in pylint.checker.base
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Mar 24, 2022
1 parent 977b08d commit 84d22cf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
21 changes: 1 addition & 20 deletions pylint/checkers/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
28 changes: 28 additions & 0 deletions pylint/checkers/base/pass_checker.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 84d22cf

Please sign in to comment.