Пример #1
0
    def _check_base_classes(self, node: ast.ClassDef) -> None:
        """Check 'object' class in parent list."""
        if len(node.bases) == 0:
            self.add_violation(
                RequiredBaseClassViolation(node, text=node.name), )

        if len(node.bases) >= 2:
            for base_name in node.bases:
                id_attr = getattr(base_name, 'id', None)
                if id_attr == 'object':
                    self.add_violation(
                        ObjectInBaseClassesListViolation(node, text=id_attr), )
Пример #2
0
    def _check_base_classes(self, node: ast.ClassDef) -> None:
        if len(node.bases) == 0:
            self.add_violation(
                RequiredBaseClassViolation(node, text=node.name), )

        for base_name in node.bases:
            if not isinstance(base_name, (ast.Name, ast.Attribute)):
                self.add_violation(IncorrectBaseClassViolation(node))
                continue

            id_attr = getattr(base_name, 'id', None)
            if id_attr == 'BaseException':
                self.add_violation(BaseExceptionSubclassViolation(node))
            elif id_attr == 'object' and len(node.bases) >= 2:
                self.add_violation(
                    ObjectInBaseClassesListViolation(node, text=id_attr), )
Пример #3
0
 def _check_base_class(self, node: ast.ClassDef) -> None:
     if len(node.bases) == 0:
         self.add_violation(RequiredBaseClassViolation(node,
                                                       text=node.name))
Пример #4
0
 def _check_base_classes_count(self, node: ast.ClassDef) -> None:
     if not node.bases:
         self.add_violation(
             RequiredBaseClassViolation(node, text=node.name), )