Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Python2-style exception handling #90668

Closed
iritkatriel opened this issue Jan 25, 2022 · 6 comments
Closed

Update Python2-style exception handling #90668

iritkatriel opened this issue Jan 25, 2022 · 6 comments
Assignees
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@iritkatriel
Copy link
Member

BPO 46510
Nosy @iritkatriel, @kumaraditya303
PRs
  • bpo-46510: simplify exception handling code in xmlrpc #30878
  • bpo-46510: Add missing test for types.TracebackType/FrameType. Calculate them directly from the caught exception. #30880
  • bpo-46510: Remove old Python 2 style exception handling from argparse #30881
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/iritkatriel'
    closed_at = <Date 2022-01-25.18:01:18.941>
    created_at = <Date 2022-01-25.07:41:04.187>
    labels = ['type-feature', 'library', '3.11']
    title = 'Update Python2-style exception handling'
    updated_at = <Date 2022-01-25.18:01:18.941>
    user = 'https://github.com/iritkatriel'

    bugs.python.org fields:

    activity = <Date 2022-01-25.18:01:18.941>
    actor = 'iritkatriel'
    assignee = 'iritkatriel'
    closed = True
    closed_date = <Date 2022-01-25.18:01:18.941>
    closer = 'iritkatriel'
    components = ['Library (Lib)']
    creation = <Date 2022-01-25.07:41:04.187>
    creator = 'iritkatriel'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46510
    keywords = ['patch']
    message_count = 6.0
    messages = ['411561', '411580', '411581', '411618', '411648', '411650']
    nosy_count = 2.0
    nosy_names = ['iritkatriel', 'kumaraditya']
    pr_nums = ['30878', '30880', '30881']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue46510'
    versions = ['Python 3.11']

    @iritkatriel
    Copy link
    Member Author

    Following bpo-45711 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
    

    @iritkatriel iritkatriel added the 3.11 only security fixes label Jan 25, 2022
    @iritkatriel iritkatriel self-assigned this Jan 25, 2022
    @iritkatriel iritkatriel added stdlib Python modules in the Lib dir type-feature A feature request or enhancement 3.11 only security fixes labels Jan 25, 2022
    @iritkatriel iritkatriel self-assigned this Jan 25, 2022
    @iritkatriel iritkatriel added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Jan 25, 2022
    @iritkatriel
    Copy link
    Member Author

    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.

    @kumaraditya303
    Copy link
    Contributor

    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.

    @iritkatriel
    Copy link
    Member Author

    New changeset 45f5f52 by Kumar Aditya in branch 'main':
    bpo-46510: update Python2-style exception handling in argparse (GH-30881)
    45f5f52

    @iritkatriel
    Copy link
    Member Author

    New changeset d69d3d8 by Irit Katriel in branch 'main':
    bpo-46510: simplify exception handling code in xmlrpc (GH-30878)
    d69d3d8

    @iritkatriel
    Copy link
    Member Author

    New changeset ec7c17e by Irit Katriel in branch 'main':
    bpo-46510: Add missing test for types.TracebackType/FrameType. Calculate them directly from the caught exception. (GH-30880)
    ec7c17e

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants