Skip to content

[Backport maintenance/3.3.x] Fix crash in catching-non-exception when something besides a class in except #10234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/10106.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a crash when something besides a class is found in an except handler.

Closes #10106
8 changes: 7 additions & 1 deletion pylint/checkers/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,13 @@ def _check_catching_non_exception(
return
if all(
node
and (utils.inherit_from_std_ex(node) or not utils.has_known_bases(node))
and (
utils.inherit_from_std_ex(node)
or (
isinstance(node, nodes.ClassDef)
and not utils.has_known_bases(node)
)
)
for node in inferred
):
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,11 @@ class SomeBase(UnknownError):
raise ValueError
except EXCEPTIONS:
pass


LAMBDA = lambda x: 1, 2

try:
pass
except LAMBDA: # [catching-non-exception]
pass
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ catching-non-exception:71:7:71:52::"Catching an exception which doesn't inherit
catching-non-exception:84:7:84:26::"Catching an exception which doesn't inherit from Exception: NON_EXCEPTION_TUPLE":UNDEFINED
catching-non-exception:102:7:102:13::"Catching an exception which doesn't inherit from Exception: object":UNDEFINED
catching-non-exception:107:7:107:12::"Catching an exception which doesn't inherit from Exception: range":UNDEFINED
catching-non-exception:141:7:141:13::"Catching an exception which doesn't inherit from Exception: LAMBDA":UNDEFINED
Loading