Exemple #1
0
 def _check_exception_type(self, node: ast.Raise) -> None:
     exception_name = get_exception_name(node)
     if exception_name == 'NotImplemented':
         self.add_violation(RaiseNotImplementedViolation(node))
     elif exception_name in self._base_exceptions:
         self.add_violation(
             BaseExceptionRaiseViolation(node, text=exception_name), )
Exemple #2
0
    def _check_generator(self, node: AnyFunctionDef) -> None:
        if not functions.is_generator(node):
            return

        for sub_node in walk.get_subnodes_by_type(node, ast.Raise):
            if exceptions.get_exception_name(sub_node) == 'StopIteration':
                self.add_violation(
                    StopIterationInsideGeneratorViolation(sub_node), )
Exemple #3
0
    def _check_raise_from_itself(self, node: ast.Raise) -> None:
        if node.exc and node.cause:
            names_are_same = get_exception_name(node) == get_cause_name(node)

            if names_are_same:
                self.add_violation(RaiseFromItselfViolation(node))
 def _check_exception_type(self, node: ast.Raise) -> None:
     exception_name = get_exception_name(node)
     if exception_name == 'NotImplemented':
         self.add_violation(RaiseNotImplementedViolation(node))