From 612b87a3b3eaa6e862198c99d120e492cbfa19d9 Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Wed, 13 Feb 2019 10:12:01 +0100 Subject: Allow ``BaseException`` for emitting ``broad-except``, just like ``Exception``. Close #2741 --- ChangeLog | 4 ++++ pylint/checkers/exceptions.py | 2 +- pylint/test/functional/broad_except.py | 6 ++++++ pylint/test/functional/broad_except.txt | 3 ++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e4f6d2575..121d228cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,10 @@ What's New in Pylint 2.3.0? Release date: TBA +* Allow ``BaseException`` for emitting ``broad-except``, just like ``Exception``. + + Close #2741 + * Fixed a crash that occurred for ``bad-str-strip-call`` when ``strip()`` received ``None`` Close #2743 diff --git a/pylint/checkers/exceptions.py b/pylint/checkers/exceptions.py index 80ea98ae2..c43af53af 100644 --- a/pylint/checkers/exceptions.py +++ b/pylint/checkers/exceptions.py @@ -70,7 +70,7 @@ def _is_raising(body: typing.List) -> bool: PY3K = sys.version_info >= (3, 0) -OVERGENERAL_EXCEPTIONS = ("Exception",) +OVERGENERAL_EXCEPTIONS = ("BaseException", "Exception") BUILTINS_NAME = builtins.__name__ MSGS = { diff --git a/pylint/test/functional/broad_except.py b/pylint/test/functional/broad_except.py index f71431e0b..24c839951 100644 --- a/pylint/test/functional/broad_except.py +++ b/pylint/test/functional/broad_except.py @@ -6,3 +6,9 @@ try: __revision__ += 1 except Exception: # [broad-except] print('error') + + +try: + __revision__ += 1 +except BaseException: # [broad-except] + print('error') diff --git a/pylint/test/functional/broad_except.txt b/pylint/test/functional/broad_except.txt index bb44550c0..5a46b03be 100644 --- a/pylint/test/functional/broad_except.txt +++ b/pylint/test/functional/broad_except.txt @@ -1 +1,2 @@ -broad-except:7::Catching too general exception Exception \ No newline at end of file +broad-except:7::Catching too general exception Exception +broad-except:13::Catching too general exception BaseException -- cgit v1.2.1