X Tutup
Skip to content

IPython REPL doesn't render exception notes #13849

@wimglenn

Description

@wimglenn

Adding additional context to exceptions is possible in Python 3.11+, described in PEP 678 – Enriching Exceptions with Notes.

In vanilla REPL:

>>> try:
...     1/0
... except Exception as e:
...     e.add_note("uh-oh")
...     raise
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ZeroDivisionError: division by zero
uh-oh

They don't show in the IPython REPL:

In [1]: try:
   ...:     1/0
   ...: except Exception as e:
   ...:     e.add_note("uh-oh")
   ...:     raise e
   ...: 
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
Cell In[1], line 5
      3 except Exception as e:
      4     e.add_note("uh-oh")
----> 5     raise e

Cell In[1], line 2
      1 try:
----> 2     1/0
      3 except Exception as e:
      4     e.add_note("uh-oh")

ZeroDivisionError: division by zero

In [2]: import sys

In [3]: sys.last_value.__notes__
Out[3]: ['uh-oh']

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup