This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Update Python2-style exception handling
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: iritkatriel Nosy List: iritkatriel, kumaraditya
Priority: normal Keywords: patch

Created on 2022-01-25 07:41 by iritkatriel, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30878 merged iritkatriel, 2022-01-25 07:49
PR 30880 merged iritkatriel, 2022-01-25 11:01
PR 30881 merged kumaraditya, 2022-01-25 11:13
Messages (6)
msg411561 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-25 07:41
Following issue45711 the redundancy in exc_info is now explicit. This means that we can now safely update places that still use python2-style exception handling code, like:

            exc_type, exc_value = sys.exc_info()[:2]
            try:
                response = dumps(
                    Fault(1, "%s:%s" % (exc_type, exc_value)),
                    encoding=self.encoding, allow_none=self.allow_none)
                response = response.encode(self.encoding, 'xmlcharrefreplace')
            finally:
                # Break reference cycle
                exc_type = exc_value = None
msg411580 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-25 12:11
It's not my intention here to go on a search-and-destroy mission to remove all calls to sys.exc_info(), that would cause unnecessary code churn. I am reviewing them to see where the call the sys.exc_info is close to other legacy problems/significant complexity/missing tests.
msg411581 - (view) Author: Kumar Aditya (kumaraditya) * (Python triager) Date: 2022-01-25 12:15
> It's not my intention here to go on a search-and-destroy mission to remove all calls to sys.exc_info(), that would cause unnecessary code churn. I am reviewing them to see where the call the sys.exc_info is close to other legacy problems/significant complexity/missing tests.

That's my intention too, in argparse it was used to get the currently handled exception value which can be easily accessed by using "as" in exception handling, so it makes sense to change it, not to mention that using exc_info creates a temporary tuple which is of no use in this scenario.
msg411618 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-25 15:34
New changeset 45f5f52601ebccb195c19cb0a77beaf7f7dfa56a by Kumar Aditya in branch 'main':
bpo-46510: update Python2-style exception handling in argparse (GH-30881)
https://github.com/python/cpython/commit/45f5f52601ebccb195c19cb0a77beaf7f7dfa56a
msg411648 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-25 17:58
New changeset d69d3d8b2fec501e51309221fb1fa4622c8a3db3 by Irit Katriel in branch 'main':
bpo-46510: simplify exception handling code in xmlrpc (GH-30878)
https://github.com/python/cpython/commit/d69d3d8b2fec501e51309221fb1fa4622c8a3db3
msg411650 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-25 18:01
New changeset ec7c17ea236f71c8376abcc2930a7c857d417966 by Irit Katriel in branch 'main':
bpo-46510: Add missing test for types.TracebackType/FrameType. Calculate them directly from the caught exception. (GH-30880)
https://github.com/python/cpython/commit/ec7c17ea236f71c8376abcc2930a7c857d417966
History
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90668
2022-01-25 18:01:18iritkatrielsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-01-25 18:01:04iritkatrielsetmessages: + msg411650
2022-01-25 17:58:24iritkatrielsetmessages: + msg411648
2022-01-25 15:34:16iritkatrielsetmessages: + msg411618
2022-01-25 12:15:36kumaradityasetmessages: + msg411581
2022-01-25 12:11:52iritkatrielsetmessages: + msg411580
2022-01-25 11:13:51kumaradityasetnosy: + kumaraditya
pull_requests: + pull_request29061
2022-01-25 11:01:59iritkatrielsetpull_requests: + pull_request29060
2022-01-25 07:49:26iritkatrielsetkeywords: + patch
stage: patch review
pull_requests: + pull_request29058
2022-01-25 07:41:04iritkatrielcreate