Examples for bad-exception-context#6026
Merged
DanielNoord merged 2 commits intopylint-dev:mainfrom Mar 29, 2022
Merged
Conversation
Co-authored-by: Vladyslav Krylasov <vladyslav.krylasov@gmail.com>
Pierre-Sassoulas
approved these changes
Mar 29, 2022
Member
Pierre-Sassoulas
left a comment
There was a problem hiding this comment.
Nitpick to not use an Exception in the re-raise feel free to ignore.
4 tasks
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Comment on lines
+1
to
+7
| def divide(x, y): | ||
| result = 0 | ||
| try: | ||
| result = x / y | ||
| except ZeroDivisionError: | ||
| raise ValueError(f"Division by zero when dividing {x} by {y} !") from result # [bad-exception-context] | ||
| return result |
Member
There was a problem hiding this comment.
Suggested change
| def divide(x, y): | |
| result = 0 | |
| try: | |
| result = x / y | |
| except ZeroDivisionError: | |
| raise ValueError(f"Division by zero when dividing {x} by {y} !") from result # [bad-exception-context] | |
| return result | |
| class YParameterIsZero(ZeroDivisionError): | |
| ... | |
| def divide(x, y): | |
| result = 0 | |
| try: | |
| result = x / y | |
| except ZeroDivisionError: | |
| raise YParameterIsZero(f"Division by zero when dividing {x} by {y} !") from result # [bad-exception-context] | |
| return result |
Comment on lines
+1
to
+7
| def divide(x, y): | ||
| result = 0 | ||
| try: | ||
| result = x / y | ||
| except ZeroDivisionError as exc: | ||
| raise ValueError(f"Division by zero when dividing {x} by {y} !") from exc | ||
| return result |
Member
There was a problem hiding this comment.
Suggested change
| def divide(x, y): | |
| result = 0 | |
| try: | |
| result = x / y | |
| except ZeroDivisionError as exc: | |
| raise ValueError(f"Division by zero when dividing {x} by {y} !") from exc | |
| return result | |
| class YParameterIsZero(ZeroDivisionError): | |
| ... | |
| def divide(x, y): | |
| result = 0 | |
| try: | |
| result = x / y | |
| except ZeroDivisionError as exc: | |
| raise YParameterIsZero(f"Division by zero when dividing {x} by {y} !") from exc | |
| return result |
Member
|
Nevermind the suggestion it's not that important :) |
Collaborator
|
Oops, sorry guys! Little too trigger happy 😅 |
Collaborator
Author
|
😀 No problem, while I think Pierre's last suggestion would have been the best solution, I guess it should be already good enough for the sake of documentation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Co-authored-by: Vladyslav Krylasov vladyslav.krylasov@gmail.com
and preferred name in
script/.contributors_aliases.jsonType of Changes
Description
Examples and related links for
bad-exception-context.Ref: #5953