Example #1
0
    def _check_base_classes(self, node: ast.ClassDef) -> None:
        for base_name in node.bases:
            if not self._is_correct_base_class(base_name):
                self.add_violation(oop.WrongBaseClassViolation(base_name))
                continue

            id_attr = getattr(base_name, 'id', None)
            if id_attr == 'BaseException':
                self.add_violation(bp.BaseExceptionSubclassViolation(node))
            elif id_attr == 'object' and len(node.bases) >= 2:
                self.add_violation(
                    consistency.ObjectInBaseClassesListViolation(
                        node,
                        text=id_attr,
                    ), )
            elif classes.is_forbidden_super_class(id_attr):
                self.add_violation(
                    oop.BuiltinSubclassViolation(node, text=id_attr), )
Example #2
0
    def _check_base_classes_rules(
        self,
        node: ast.ClassDef,
        base_name: ast.expr,
    ) -> None:
        id_attr = getattr(base_name, 'id', None)

        if id_attr == 'BaseException':
            self.add_violation(bp.BaseExceptionSubclassViolation(node))
        elif id_attr == 'object' and len(node.bases) >= 2:
            self.add_violation(
                consistency.ObjectInBaseClassesListViolation(
                    node,
                    text=id_attr,
                ), )
        elif classes.is_forbidden_super_class(id_attr):
            self.add_violation(
                oop.BuiltinSubclassViolation(node, text=id_attr), )