Skip to content
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
8 changes: 8 additions & 0 deletions doc/data/messages/b/bad-except-order/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
try:
print(int(input()))
except Exception:
raise
except TypeError: # [bad-except-order]
# This block cannot be reached since TypeError exception
# is caught by previous exception handler.
raise
6 changes: 6 additions & 0 deletions doc/data/messages/b/bad-except-order/good.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
try:
print(int(input()))
except TypeError:
raise
except Exception:
raise
Comment on lines +5 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would emit try-except-raise, I think, so maybe we should model doing something with the exception?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on this discussion #5992 (comment) we should prefer simplicity/readability over code cleanness.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair, but I think a flexible approach to this is worth considering, because I suspect we'll get an issue someday "I rewrote my code the way pylint said to but then I got another error".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I leave the decision to @Pierre-Sassoulas and @DanielNoord

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a pass instead of a raise ? Still simple, but no try-except-raise ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's a losing battle because bare-exception is also in play (probably?). So I'm willing to leave this be πŸ˜„