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

Fix exception cause in common.py #149

Merged
merged 1 commit into from
Jun 14, 2020

Conversation

cool-RR
Copy link
Contributor

@cool-RR cool-RR commented Jun 11, 2020

I recently went over Matplotlib, Pandas and NumPy, fixing a small mistake in the way that Python 3's exception chaining is used. If you're interested, I can do it here too. I've done it on just one file right now.

The mistake is this: In some parts of the code, an exception is being caught and replaced with a more user-friendly error. In these cases the syntax raise new_error from old_error needs to be used.

Python 3's exception chaining means it shows not only the traceback of the current exception, but that of the original exception (and possibly more.) This is regardless of raise from. The usage of raise from tells Python to put a more accurate message between the tracebacks. Instead of this:

During handling of the above exception, another exception occurred:

You'll get this:

The above exception was the direct cause of the following exception:

The first is inaccurate, because it signifies a bug in the exception-handling code itself, which is a separate situation than wrapping an exception.

Let me know what you think!

@coveralls
Copy link

coveralls commented Jun 11, 2020

Coverage Status

Coverage remained the same at 91.25% when pulling 81f55c8 on cool-RR:2020-06-11-raise-from into ec57ac0 on sybrenstuvel:master.

@sybrenstuvel
Copy link
Owner

This is very welcome, thanks for the offer!

@cool-RR
Copy link
Contributor Author

cool-RR commented Jun 12, 2020

Good to know. Would you be okay with first merging this PR before I do the rest?

@sybrenstuvel
Copy link
Owner

I'm not a fan of single-letter variables, so maybe change ... as e to ... as ex and you have my merge ;-)

@cool-RR cool-RR force-pushed the 2020-06-11-raise-from branch from 5cb40e9 to 81f55c8 Compare June 14, 2020 11:40
@cool-RR
Copy link
Contributor Author

cool-RR commented Jun 14, 2020

Fixed.

@sybrenstuvel sybrenstuvel merged commit a87a564 into sybrenstuvel:master Jun 14, 2020
@cool-RR
Copy link
Contributor Author

cool-RR commented Jun 14, 2020

Awesome. You'll get another PR in the next few weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants