You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Following to changes in bpo-45711, the interpreter's internal representation of the active exception is just the exception instance (the exc_type and exc_traceback fields were removed).
For backwards compatibility, sys.exc_info() constructs the (typ, val, tb) tuple from the instance and this will continue to be the case for some time because this tuple has leaked into quite a few APIs.
However, now that the redundancy in the exc_info tuple is guaranteed by the way it's constructed, we can confidently add a sys.exception() method that returns just the exception instance (as suggested in PEP-3134's section on future improvements).
This small change will make a difference to learners because the (typ, val, tb) tuple looks quite cryptic to those who don't know about tracebacks, and the redundancy in it is confusing for those who do.
FWIW, here's an alternative we should not pursue: return just the exception from sys.exc_info(). For compatibility, we would implement __iter__ and __getitem__ on BaseException, to duplicate the behavior of the current tuple. There are a number of good reasons why this is not what we should do.