Module rulebook-pylint.rulebook_pylint.exception_inheritance

Functions

def register(linter: PyLinter)
Expand source code
def register(linter: 'PyLinter') -> None:
    linter.register_checker(ExceptionInheritanceChecker(linter))

Classes

class ExceptionInheritanceChecker (linter: PyLinter)
Expand source code
class ExceptionInheritanceChecker(RulebookChecker):
    """See detail: https://hanggrian.github.io/rulebook/rules/#exception-inheritance"""
    MSG: str = 'exception-inheritance'

    name: str = 'exception-inheritance'
    msgs: dict[str, MessageDefinitionTuple] = Messages.of(MSG)

    def visit_classdef(self, node: ClassDef) -> None:
        # checks for violation
        for base in [
            n for n in node.bases \
            if isinstance(n, Name) and n.name == 'BaseException' \
            ]:
            self.add_message(self.MSG, node=base)
            return

See detail: https://hanggrian.github.io/rulebook/rules/#exception-inheritance

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:
    # checks for violation
    for base in [
        n for n in node.bases \
        if isinstance(n, Name) and n.name == 'BaseException' \
        ]:
        self.add_message(self.MSG, node=base)
        return