Skip to content

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!

@cool-RR
Copy link
Contributor Author

cool-RR commented Jun 12, 2020

@jonathanslenders Any idea why mypy is failing here? Is it related to my change?

5.11s$ mypy prompt_toolkit
prompt_toolkit/document.py:828: error: Unpacking a string is disallowed
prompt_toolkit/document.py:829: error: Cannot determine type of 'A'
prompt_toolkit/document.py:830: error: Cannot determine type of 'A'
prompt_toolkit/document.py:830: error: Cannot determine type of 'B'
prompt_toolkit/document.py:831: error: Cannot determine type of 'B'
prompt_toolkit/document.py:832: error: Cannot determine type of 'A'
prompt_toolkit/document.py:832: error: Cannot determine type of 'B'
prompt_toolkit/application/application.py:691: error: Module has no attribute "SIGWINCH"
prompt_toolkit/application/application.py:692: error: Module has no attribute "SIGWINCH"
prompt_toolkit/application/application.py:731: error: Module has no attribute "SIGWINCH"
prompt_toolkit/application/application.py:732: error: Module has no attribute "SIGWINCH"
prompt_toolkit/application/application.py:1007: error: Module has no attribute "SIGTSTP"
prompt_toolkit/application/application.py:1009: error: Module has no attribute "SIGTSTP"
prompt_toolkit/shortcuts/progress_bar/base.py:146: error: Module has no attribute "SIGWINCH"
prompt_toolkit/shortcuts/progress_bar/base.py:230: error: Module has no attribute "SIGWINCH"
prompt_toolkit/shortcuts/progress_bar/base.py:231: error: Module has no attribute "SIGWINCH"
prompt_toolkit/shortcuts/progress_bar/base.py:242: error: Module has no attribute "SIGWINCH"
prompt_toolkit/shortcuts/progress_bar/base.py:243: error: Module has no attribute "SIGWINCH"
Found 18 errors in 3 files (checked 141 source files)
The command "mypy prompt_toolkit" exited with 1.

@jonathanslenders
Copy link
Member

The mypy errors are probably because we got a new mypy version. I have them on my local system too now. I look into that.

Thanks for the PR!

@jonathanslenders jonathanslenders merged commit 11f75c0 into prompt-toolkit:master Jun 16, 2020
@jonathanslenders
Copy link
Member

Thanks!

The mypy errors were fixed here: #1167 (comment)

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.

2 participants