Skip to content

Conversation

@DudeNr33
Copy link
Collaborator

Co-authored-by: Vladyslav Krylasov [email protected]

  • Write a good description on what the PR does.
  • If you used multiple emails or multiple names when contributing, add your mails
    and preferred name in script/.contributors_aliases.json

Type of Changes

Type
🐛 Bug fix
✨ New feature
🔨 Refactoring
📜 Docs

Description

Examples and related links for bad-exception-context.

Ref: #5953

Co-authored-by: Vladyslav Krylasov <[email protected]>
@DudeNr33 DudeNr33 added this to the 2.14.0 milestone Mar 29, 2022
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Nitpick to not use an Exception in the re-raise feel free to ignore.

Co-authored-by: Pierre Sassoulas <[email protected]>
@DanielNoord DanielNoord merged commit e41b2f0 into pylint-dev:main Mar 29, 2022
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
Copy link
Member

Choose a reason for hiding this comment

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

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
Copy link
Member

Choose a reason for hiding this comment

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

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

@Pierre-Sassoulas
Copy link
Member

Nevermind the suggestion it's not that important :)

@DanielNoord
Copy link
Collaborator

Oops, sorry guys! Little too trigger happy 😅

@DudeNr33
Copy link
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.

@Pierre-Sassoulas Pierre-Sassoulas removed this from the 2.14.0 milestone May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants