-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Fix exception chaining #3679
Comments
Hi! thanks for your contribution!, great first issue! |
oh! I just learned something new about Python exceptions. Awesome! Related: #2266 |
Thanks @edenlightning for relabelling the issue! I didn't know Hacktoberfest at all! @awaelchli Thank you for your quick response! |
@akihironitta assigned you to this issue. Yeah, you can do this in October. |
@awaelchli @rohitgr7 I just made #3750 ready for review! Can you have a look at the changes? |
I recently went over PyTorch and Detectron2, suggesting a fix in the way that Python 3's exception chaining is used.
As described in detail in this article, exception chaining (PEP 3134) can be used to make exceptions more user-friendly, and in that case, the syntax
raise new_exception from old_exception
needs to be used.When
raise .. from ..
is used, there will be a line sayingThe above exception was the direct cause of the following exception
between tracebacks. However, when implicitly chaining exceptions (meaning whenraise .. from ..
is not used), the message will beDuring handling of the above exception, another exception occurred
which can confuse users.Specifically, the following should be used in order to chain exceptions:
instead of:
One example which needs to be fixed is:
https://github.com/PyTorchLightning/pytorch-lightning/blob/3d76f604bdb97d66dd1248540ea088fb18c06a03/pytorch_lightning/utilities/parsing.py#L159-L162
If this suggestion sounds good and reasonable, I'd be happy to create a PR! Let me know your thoughts on this!
The text was updated successfully, but these errors were encountered: