Module rulebook-pylint.rulebook_pylint.abstract_class_definition
Functions
def register(linter: PyLinter)
-
Expand source code
def register(linter: 'PyLinter') -> None: linter.register_checker(AbstractClassDefinitionChecker(linter))
Classes
class AbstractClassDefinitionChecker (linter: PyLinter)
-
Expand source code
class AbstractClassDefinitionChecker(RulebookChecker): """See detail: https://hanggrian.github.io/rulebook/rules/#abstract-class-definition""" MSG: str = 'abstract-class-definition' name: str = 'abstract-class-definition' msgs: dict[str, MessageDefinitionTuple] = Messages.of(MSG) def visit_classdef(self, node: ClassDef) -> None: # skip non-abstract class if not any( (isinstance(n, Name) and \ n.name == 'ABC' \ for n in node.bases), ): return # checks for violation if len(node.bases) > 1 or \ any( (isinstance(n, FunctionDef) and \ has_decorator(n, 'abstractmethod') \ for n in node.body), ): return self.add_message(self.MSG, node=node.bases[0])
See detail: https://hanggrian.github.io/rulebook/rules/#abstract-class-definition
Checker instances should have the linter as argument.
Ancestors
- rulebook_pylint.checkers.RulebookChecker
- pylint.checkers.base_checker.BaseChecker
- pylint.config.arguments_provider._ArgumentsProvider
Class variables
var MSG : str
-
The type of the None singleton.
var msgs : dict[str, tuple[str, str, str] | tuple[str, str, str, pylint.typing.ExtraMessageOptions]]
-
The type of the None singleton.
var name : str
-
The type of the None singleton.
Methods
def visit_classdef(self, node: astroid.nodes.scoped_nodes.scoped_nodes.ClassDef) ‑> None
-
Expand source code
def visit_classdef(self, node: ClassDef) -> None: # skip non-abstract class if not any( (isinstance(n, Name) and \ n.name == 'ABC' \ for n in node.bases), ): return # checks for violation if len(node.bases) > 1 or \ any( (isinstance(n, FunctionDef) and \ has_decorator(n, 'abstractmethod') \ for n in node.body), ): return self.add_message(self.MSG, node=node.bases[0])