| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Oops, I checked for existing issues a few hours before this was opened and then created #14040 - it has tests and a changelog, but is a bit less careful about edge cases. Cherry-pick whatever you want and then I'll close my PR? |
Sorry, something went wrong.
|
I'm guessing you both are at PyCon sprints !? Enjoy ! I'll likely get that in during May :-). |
Sorry, something went wrong.
|
Changes cherry-picked, good catch Zac on the Plain traceback format! |
Sorry, something went wrong.
| *.swp | ||
| .pytest_cache | ||
| .python-version | ||
| .venv*/ |
There was a problem hiding this comment.
You likely want that in your global gitignore to not have to do it for all your repos.
Sorry, something went wrong.
|
Let's try this. Sorry I was mostly travelling last month. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
PEP 678 introduced the ability to add notes to exception objects. This has been released in Python 3.11 and is currently not implemented in IPython. These changes are fully compatible with older Python versions that don't include PEP 678.
Here's a sample test that shows the consistency in Python's stdlib traceback module (test 1) and the difference between Python and IPython's runtimes (test 2):
When executed with Python 3.11, both notes are displayed in both tracebacks:
$ python test.py --- test 1 --- Traceback (most recent call last): File "/app/test.py", line 5, in <module> raise Exception('Testing notes') Exception: Testing notes Does this work? Yes! --- test 2 --- Traceback (most recent call last): File "/app/test.py", line 13, in <module> raise Exception('Testing notes') Exception: Testing notes Does this work? No!In IPython's VerboseTB does not yet handle exception notes:
$ ipython test.py --- test 1 --- Traceback (most recent call last): File "/app/test.py", line 5, in <module> raise Exception('Testing notes') Exception: Testing notes Does this work? Yes! --- test 2 --- --------------------------------------------------------------------------- Exception Traceback (most recent call last) File /app/test.py:13 11 print('\n--- test 2 ---') 12 try: ---> 13 raise Exception('Testing notes') 14 except Exception as e: 15 e.add_note('Does this work?') Exception: Testing notesThe changes I am suggesting are inspired from implementation of Lib/traceback.py (search for __notes__) and improvements for dealing with edge cases more nicely in cpython#103897.
Although notes are meant to be strings only, I kept some inspiration from the existing exception handling to ensure that the notes are uncolored and bytes decoded, if there are any. I am definitely open to using a different color if deemed better. For context, bpython keeps the notes uncolored, and Python's tutorial puts them in light gray, like the line numbers.
Here's how the test 2 looks like after these changes:

🐍 🤹♂️