PEP 678: Enriching Exceptions with Notes

Thank you to the SC and to everyone who participated in the discussion. The final PEP is definitely better than what we started with!

1 Like

As explained above, I don’t think this is a realistic option as:

  • It would conflict with pytest, ipython,… (which already customize the traceback)
  • It would conflict with user own traceback customization
  • If all libraries were doing this, libraries would conflict with each other
  • Having a library which has global side-effects would be confusing/unexpected for users

Looking at the code example from @Zac-HD, exceptiongroup is mutating the traceback module at import time.

Did I miss something ? Is there a way to locally control how an exception is rendered without global side-effect ?

One option would have be to have some class LazyStr(str), so that the actuall str is never computed if not accessed.

There would probably be also many other options and API to allow customizing traceback.

My feeling is that if we had done a pooling for on the Python community about which feature are more important between:

  1. Supporting i18n translation
  2. Flexible formating (control the position where the notes are added)

I think more users would have been interested by (2), so I’m surprised only (1) was fixed.

I see this as keeping this PEP focused and relatively simple.

There is room for potential improvement in our Traceback machinery in future releases if someone wants to drive defining what they’d like to see there. (example wish: it’d be nice to be able to expose them in a structural unambiguious format for machine processing rather than the semi-arbitrary text they can be today)

If we tried to address everyone’s desires all at once when doing anything or do nothing at all, nothing would ever happen.

4 Likes