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

Replace with_traceback() with exception chaining and reraising #91255

Closed
arhadthedev opened this issue Mar 23, 2022 · 2 comments
Closed

Replace with_traceback() with exception chaining and reraising #91255

arhadthedev opened this issue Mar 23, 2022 · 2 comments
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@arhadthedev
Copy link
Member

BPO 47099
Nosy @iritkatriel, @arhadthedev
PRs
  • bpo-47099: Replace with_traceback() with exception chaining and reraising #32074
  • 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 = None
    closed_at = <Date 2022-03-30.15:11:25.405>
    created_at = <Date 2022-03-23.10:42:51.369>
    labels = ['type-feature', 'library', '3.11']
    title = 'Replace with_traceback() with exception chaining and reraising'
    updated_at = <Date 2022-03-30.15:11:25.405>
    user = 'https://github.com/arhadthedev'

    bugs.python.org fields:

    activity = <Date 2022-03-30.15:11:25.405>
    actor = 'arhadthedev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-03-30.15:11:25.405>
    closer = 'arhadthedev'
    components = ['Library (Lib)']
    creation = <Date 2022-03-23.10:42:51.369>
    creator = 'arhadthedev'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 47099
    keywords = ['patch']
    message_count = 2.0
    messages = ['415864', '415872']
    nosy_count = 2.0
    nosy_names = ['iritkatriel', 'arhadthedev']
    pr_nums = ['32074']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue47099'
    versions = ['Python 3.11']

    @arhadthedev
    Copy link
    Member Author

    Currently, exception chaining in Lib/ modules is implemented with pre-3.11 raise Foo(...).with_traceback(sys.exc_info()[2]). However, this approach can be simplified:

    1. PEP-3134 introduced a proper raise Foo(...) from bar construction that takes a parent exception instead of its stack traceback

    2. Without the traceback required, we partially get rid of sys.exc_info thus reducing active tapping into global internals

    A report printed into a console remains the same except a line:

    During handling of the above exception, another exception occurred

    replaced with:

    The above exception was the direct cause of the following exception

    @arhadthedev arhadthedev added 3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Mar 23, 2022
    @iritkatriel
    Copy link
    Member

    You don't need sys.exc_info() for the traceback anymore.

    except Exception as e:
        raise OSError('blah').with_traceback(e.__traceback__)

    @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