Esempio n. 1
0
    def _check_duplicate_exceptions(self, node: ast.Try) -> None:
        exceptions_list = exceptions.get_all_exception_names(node)

        for exc_name, count in Counter(exceptions_list).items():
            if count > 1:
                self.add_violation(
                    DuplicateExceptionViolation(node, text=exc_name), )
Esempio n. 2
0
    def _check_exception_order(self, node: ast.Try) -> None:
        built_in_exceptions = exceptions.traverse_exception(BaseException)
        exceptions_list = exceptions.get_all_exception_names(node)
        seen: Set[str] = set()

        for exception in exceptions_list:
            bases = built_in_exceptions.get(exception)

            if bases is not None:
                if any(base in seen for base in bases):
                    self.add_violation(IncorrectExceptOrderViolation(node))
                else:
                    seen.add(exception)