pass_checker.py 1.0 KB

1234567891011121314151617181920212223242526272829
  1. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  2. # For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE
  3. # Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt
  4. from astroid import nodes
  5. from pylint.checkers import utils
  6. from pylint.checkers.base.basic_checker import _BasicChecker
  7. class PassChecker(_BasicChecker):
  8. """Check if the pass statement is really necessary."""
  9. msgs = {
  10. "W0107": (
  11. "Unnecessary pass statement",
  12. "unnecessary-pass",
  13. 'Used when a "pass" statement can be removed without affecting '
  14. "the behaviour of the code.",
  15. )
  16. }
  17. @utils.only_required_for_messages("unnecessary-pass")
  18. def visit_pass(self, node: nodes.Pass) -> None:
  19. if len(node.parent.child_sequence(node)) > 1 or (
  20. isinstance(node.parent, (nodes.ClassDef, nodes.FunctionDef))
  21. and node.parent.doc_node
  22. ):
  23. self.add_message("unnecessary-pass", node=node)