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

Simplify exception handling in doctest.py #90689

Closed
sobolevn opened this issue Jan 26, 2022 · 5 comments
Closed

Simplify exception handling in doctest.py #90689

sobolevn opened this issue Jan 26, 2022 · 5 comments
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

BPO 46531
Nosy @sobolevn, @iritkatriel
PRs
  • bpo-46531: simplify exception handling in doctest.py #30916
  • 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-01-26.10:07:07.782>
    created_at = <Date 2022-01-26.09:42:50.870>
    labels = ['invalid', 'type-bug', 'library', '3.11']
    title = 'Simplify exception handling in `doctest.py`'
    updated_at = <Date 2022-01-26.10:16:22.060>
    user = 'https://github.com/sobolevn'

    bugs.python.org fields:

    activity = <Date 2022-01-26.10:16:22.060>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-01-26.10:07:07.782>
    closer = 'sobolevn'
    components = ['Library (Lib)']
    creation = <Date 2022-01-26.09:42:50.870>
    creator = 'sobolevn'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46531
    keywords = ['patch']
    message_count = 5.0
    messages = ['411720', '411722', '411724', '411728', '411730']
    nosy_count = 2.0
    nosy_names = ['sobolevn', 'iritkatriel']
    pr_nums = ['30916']
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46531'
    versions = ['Python 3.11']

    @sobolevn
    Copy link
    Member Author

    Right now there are two places where sys.exc_info() calls are not required anymore:

    1. cpython/Lib/doctest.py

      Lines 1352 to 1353 in 6e5a193

      except:
      exception = sys.exc_info()
    2. cpython/Lib/doctest.py

      Lines 2640 to 2641 in 6e5a193

      except:
      print(sys.exc_info()[1])

    There are also places where it is exposed as a part of public API (I am not going to change that, at least in this PR):

    And some private APIs (out of scope as well):

    PR is on its way!

    @sobolevn sobolevn added 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 26, 2022
    @iritkatriel
    Copy link
    Member

    I don't think this is worth doing in a module where we can't completely get rid of the exc_info triplet.

    @iritkatriel
    Copy link
    Member

    In other words, I don't see why it's an improvement to replace

        exception = sys.exc_info()

    by

        exception = type(exc), exc, exc.__traceback__

    when sys.exc_info() does exactly what your inlined version does.

    @sobolevn
    Copy link
    Member Author

    Fair enough! The only improvement is that we don't call sys.exc_info twice here:

    cpython/Lib/doctest.py

    Lines 2641 to 2644 in 6e5a193

    print(sys.exc_info()[1])
    p = pdb.Pdb(nosigint=True)
    p.reset()
    p.interaction(None, sys.exc_info()[2])

    But, I think it is a minor thing.

    Looks like I've misunderstood the long time goal of sys.exc_info refactorings. Thanks a lot for the feedback!

    @iritkatriel
    Copy link
    Member

    In the long term we will want to not have the triplet, but this is a process that will take a few python versions to complete (when 3.11 is the oldest supported version). And it is not going to be simple.

    In the meantime, where there is an advantage to removing exc_info because the code would be simplified or something else is changing nearby, we can do it. But I wouldn't remove exc_info just for the sake of it - such code churn makes it hard to backport other changes.

    @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-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants