From 064f3788bba2ceff202a7efabb9516b52730cb03 Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Thu, 23 Aug 2018 09:20:46 +0200 Subject: [PATCH] Make sure to filter out None and Uninferable when gathering exceptions Close #2434 --- pylint/checkers/exceptions.py | 2 +- pylint/test/functional/try_except_raise.py | 10 +++++++++- pylint/test/functional/try_except_raise.txt | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pylint/checkers/exceptions.py b/pylint/checkers/exceptions.py index d39aad2960..c5533628c9 100644 --- a/pylint/checkers/exceptions.py +++ b/pylint/checkers/exceptions.py @@ -362,7 +362,7 @@ def gather_exceptions_from_handler(handler): exceptions = {exception for exception in exceptions_in_handler.elts if isinstance(exception, astroid.Name)} - else: + elif exceptions_in_handler: exceptions = [exceptions_in_handler] return exceptions diff --git a/pylint/test/functional/try_except_raise.py b/pylint/test/functional/try_except_raise.py index 31f8ab93c6..033681e356 100644 --- a/pylint/test/functional/try_except_raise.py +++ b/pylint/test/functional/try_except_raise.py @@ -1,5 +1,5 @@ # pylint:disable=missing-docstring, unreachable, bad-except-order, bare-except, unnecessary-pass - +# pylint: disable=undefined-variable try: int("9a") except: # [try-except-raise] @@ -95,3 +95,11 @@ def ddd(): raise except (OverflowError, ZeroDivisionError): print("a failure") + + +try: + pass +except invalid_name: # [try-except-raise] + raise +except TypeError: + pass diff --git a/pylint/test/functional/try_except_raise.txt b/pylint/test/functional/try_except_raise.txt index 882fd4007f..ccf8f11c69 100644 --- a/pylint/test/functional/try_except_raise.txt +++ b/pylint/test/functional/try_except_raise.txt @@ -4,3 +4,4 @@ try-except-raise:53:ddd:The except handler raises immediately try-except-raise:67::The except handler raises immediately try-except-raise:72::The except handler raises immediately try-except-raise:94::The except handler raises immediately +try-except-raise:102::The except handler raises immediately