Skip to content
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

Use raise .. from .. to explicitly chain exceptions #3750

Merged
merged 5 commits into from
Oct 1, 2020

Conversation

akihironitta
Copy link
Contributor

@akihironitta akihironitta commented Sep 30, 2020

What does this PR do?

Motivation

Fixes and closes #3679.

Description of the changes

I changed lines where raiseing an exception in except to either:

  1. raise .. from e to explicitly chain exceptions where the exception e has valuable information and seems useful for users.
  2. raise .. from None to unchain exceptions where the previous exception has no valuable information and seems noisy and redundant. <- There were no places where this option is applicable in my opinion.

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together? Otherwise, we ask you to create a separate PR for every change.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?
  • Did you verify new and existing tests pass locally with your changes?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@codecov
Copy link

codecov bot commented Sep 30, 2020

Codecov Report

Merging #3750 into master will increase coverage by 3%.
The diff coverage is 43%.

@@           Coverage Diff           @@
##           master   #3750    +/-   ##
=======================================
+ Coverage      87%     90%    +3%     
=======================================
  Files         110     110            
  Lines        8858    8730   -128     
=======================================
+ Hits         7731    7842   +111     
+ Misses       1127     888   -239     

@akihironitta akihironitta marked this pull request as ready for review October 1, 2020 11:11
@mergify mergify bot requested a review from a team October 1, 2020 11:11
@akihironitta
Copy link
Contributor Author

I see CI failing but I believe these errors are caused not due to the changes I made.

@Borda Borda force-pushed the fix-exception-chaining branch from 73908d0 to 69f521e Compare October 1, 2020 11:55
Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

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

LGTM

@mergify mergify bot requested a review from a team October 1, 2020 11:56
@Borda Borda added ready PRs ready to be merged feature Is an improvement or enhancement labels Oct 1, 2020
Copy link
Member

@SkafteNicki SkafteNicki left a comment

Choose a reason for hiding this comment

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

LGTM, just two suggestions to be consistent with the naming

pytorch_lightning/metrics/metric.py Outdated Show resolved Hide resolved
pytorch_lightning/metrics/metric.py Outdated Show resolved Hide resolved
@mergify mergify bot requested a review from a team October 1, 2020 12:39
akihironitta and others added 2 commits October 1, 2020 21:44
Co-authored-by: Nicki Skafte <skaftenicki@gmail.com>
Co-authored-by: Nicki Skafte <skaftenicki@gmail.com>
@mergify
Copy link
Contributor

mergify bot commented Oct 1, 2020

This pull request is now in conflict... :(

@rohitgr7
Copy link
Contributor

rohitgr7 commented Oct 1, 2020

@akihironitta have you checked if there are no more such places where this needs to be updated?

@akihironitta
Copy link
Contributor Author

@rohitgr7 Yes, I believe. When exceptions are raised in except, they are very likely to try to make their previous exceptions more user-friendly or descriptive, so I listed and checked all the lines where exceptions are raised in except clauses with this script.

Below is the list of all lines containing raise in except:

tests/base/models.py#L15
pytorch_lightning/metrics/metric.py#L176
pytorch_lightning/accelerators/ddp2_backend.py#L52
pytorch_lightning/trainer/logging.py#L148
pytorch_lightning/tuner/batch_size_scaling.py#L185
pytorch_lightning/tuner/batch_size_scaling.py#L231
pytorch_lightning/utilities/parsing.py#L162

Copy link
Contributor

@rohitgr7 rohitgr7 left a comment

Choose a reason for hiding this comment

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

Nice!

@awaelchli awaelchli merged commit ebc1b23 into Lightning-AI:master Oct 1, 2020
nrupatunga added a commit to nrupatunga/pytorch-lightning that referenced this pull request Oct 2, 2020
Use `raise .. from ..` to explicitly chain exceptions (Lightning-AI#3750)
@Borda Borda added this to the 0.10.0 milestone Oct 7, 2020
@akihironitta akihironitta deleted the fix-exception-chaining branch October 15, 2020 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix exception chaining
5 participants