-
Notifications
You must be signed in to change notification settings - Fork 93
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
Flake8 B904 #6356
Flake8 B904 #6356
Conversation
except KeyError: | ||
raise InputError(f'No such task state "{selector}"') | ||
raise InputError(f'No such task state "{selector}"') from None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity why this and not:
except KeyError as keyerr:
raise InputError('Message') from keyerr
Should not block approval or merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.python.org/3/tutorial/errors.html#exception-chaining
KeyError
is the type of error that will never have any useful information to the user, so there is no point including it in the traceback, it would just be noise
from exc
:
KeyError Traceback (most recent call last)
Cell In[3], line 2
1 try:
----> 2 dict_['x']
3 except KeyError as exc:
KeyError: 'x'
The above exception was the direct cause of the following exception:
UsefulError Traceback (most recent call last)
Cell In[3], line 4
2 dict_['x']
3 except KeyError as exc:
----> 4 raise UsefulError('Oopsie') from exc
UsefulError: Oopsie
vs from None
:
UsefulError Traceback (most recent call last)
Cell In[4], line 4
2 dict_['y']
3 except KeyError:
----> 4 raise UsefulError('Oopsie') from None
UsefulError: Oopsie
vs no from
at all:
KeyError Traceback (most recent call last)
Cell In[5], line 2
1 try:
----> 2 dict_['z']
3 except KeyError:
KeyError: 'z'
During handling of the above exception, another exception occurred:
UsefulError Traceback (most recent call last)
Cell In[5], line 4
2 dict_['z']
3 except KeyError:
----> 4 raise UsefulError('Oopsie')
UsefulError: Oopsie
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 Comment for my learning: Feel free to merge.
No description provided.