Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Fix exception cause in config.py #488

Merged
merged 1 commit into from Jun 12, 2020
Merged

Fix exception cause in config.py #488

merged 1 commit into from Jun 12, 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. I searched this repo, and found just one instance of this mistake.

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!

@cool-RR cool-RR marked this pull request as ready for review June 11, 2020 21:57
@Nurdok Nurdok merged commit 9429e2f into PyCQA:master Jun 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants