Issue46328
Created on 2022-01-10 11:50 by iritkatriel, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 30514 | merged | iritkatriel, 2022-01-10 11:51 | |
| Messages (9) | |||
|---|---|---|---|
| msg410204 - (view) | Author: Irit Katriel (iritkatriel) * ![]() |
Date: 2022-01-10 11:50 | |
Following to changes in issue45711, 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 PEP3134'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. |
|||
| msg410216 - (view) | Author: Irit Katriel (iritkatriel) * ![]() |
Date: 2022-01-10 14:00 | |
This is part of a larger plan to reduce the footprint of the exc_info triplet on the language. See https://gist.github.com/iritkatriel/3927147548b10a7929cb0b680e3adc52 History |
|||
| msg410222 - (view) | Author: Dennis Sweeney (Dennis Sweeney) * ![]() |
Date: 2022-01-10 15:33 | |
Would there be any value in spelling this as sys.active_exception() or sys.current_exception() or sys.get_exception() or sys.exception_in_flight() or similar? My only worry is confusion between sys.exception() versus builtins.Exception. |
|||
| msg410224 - (view) | Author: Eric Snow (eric.snow) * ![]() |
Date: 2022-01-10 16:10 | |
So sys.exception() will be equivalent to sys.exc_info()[1] (or rather, sys.exc_info() will be (type(sys.exception()), sys.exception(), sys.exception().__traceback__))? That seems good to me. |
|||
| msg410225 - (view) | Author: Eric Snow (eric.snow) * ![]() |
Date: 2022-01-10 16:10 | |
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. |
|||
| msg410255 - (view) | Author: Irit Katriel (iritkatriel) * ![]() |
Date: 2022-01-10 21:29 | |
I thought of something like sys.active_exception() but it seems like a lot to type. sys.exception() was suggested in pep3134. Does this change need a pep? |
|||
| msg410258 - (view) | Author: Barry A. Warsaw (barry) * ![]() |
Date: 2022-01-10 21:50 | |
sys.exception() seems like a decent enough trade-off. I've always disliked the abbreviations in "exc_info". It doesn't feel big enough for a PEP to me. |
|||
| msg410260 - (view) | Author: Irit Katriel (iritkatriel) * ![]() |
Date: 2022-01-10 22:00 | |
Cool. I just removed the do-not-merge label from the PR and I guess it's ready to be reviewed. |
|||
| msg410489 - (view) | Author: Irit Katriel (iritkatriel) * ![]() |
Date: 2022-01-13 12:36 | |
New changeset c590b581bba517f81ced2e6f531ccc9e2e22eab5 by Irit Katriel in branch 'main': bpo-46328: Add sys.exception() (GH-30514) https://github.com/python/cpython/commit/c590b581bba517f81ced2e6f531ccc9e2e22eab5 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:54 | admin | set | github: 90486 |
| 2022-01-13 12:36:20 | iritkatriel | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2022-01-13 12:36:02 | iritkatriel | set | messages: + msg410489 |
| 2022-01-10 22:04:39 | AlexWaygood | set | nosy:
+ AlexWaygood |
| 2022-01-10 22:00:04 | iritkatriel | set | messages: + msg410260 |
| 2022-01-10 21:50:34 | barry | set | messages: + msg410258 |
| 2022-01-10 21:29:05 | iritkatriel | set | messages: + msg410255 |
| 2022-01-10 18:38:09 | barry | set | nosy:
+ barry |
| 2022-01-10 16:10:18 | eric.snow | set | messages: + msg410225 |
| 2022-01-10 16:10:04 | eric.snow | set | nosy:
+ eric.snow messages: + msg410224 |
| 2022-01-10 15:33:09 | Dennis Sweeney | set | nosy:
+ Dennis Sweeney messages: + msg410222 |
| 2022-01-10 14:02:59 | iritkatriel | set | components: + Library (Lib) |
| 2022-01-10 14:00:21 | iritkatriel | set | messages: + msg410216 |
| 2022-01-10 14:00:02 | iritkatriel | set | messages: - msg410215 |
| 2022-01-10 13:59:35 | iritkatriel | set | messages: + msg410215 |
| 2022-01-10 11:51:58 | iritkatriel | set | keywords:
+ patch stage: patch review pull_requests: + pull_request28717 |
| 2022-01-10 11:50:17 | iritkatriel | create | |
