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

Document pdb.post_mortem() accepts exceptions on Python 3.13+ #128409

Closed
adamchainz opened this issue Jan 2, 2025 · 1 comment · Fixed by #128410
Closed

Document pdb.post_mortem() accepts exceptions on Python 3.13+ #128409

adamchainz opened this issue Jan 2, 2025 · 1 comment · Fixed by #128410
Labels
docs Documentation in the Doc dir

Comments

@adamchainz
Copy link
Contributor

adamchainz commented Jan 2, 2025

Documentation

Some change in Python 3.13 (maybe 5f3433f or related) allows pdb.post_mortem() to accept an exception object, as well as a traceback object. This could be useful to use for chained exception access, for example in Django’s test runner where a traceback is currently passed, but the exception with chained causes is available.

Tested with:

import pdb

try:
    try:
        1 / 0
    except Exception:
        2 / 0
except Exception as exc:
    pdb.post_mortem(exc)

and ran with:

$ uv run -p 3.13 python example.py
> /.../example.py(7)<module>()
-> 2 / 0
(Pdb) exceptions
    0 ZeroDivisionError('division by zero')
>   1 ZeroDivisionError('division by zero')
(Pdb) exceptions 0
> /.../example.py(5)<module>()
-> 1 / 0
(Pdb)

Linked PRs

@adamchainz
Copy link
Contributor Author

pytest is already taking advantage of this “secret feature“: pytest-dev/pytest#12707

adamchainz added a commit to adamchainz/cpython that referenced this issue Jan 3, 2025
co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
adamchainz added a commit to adamchainz/cpython that referenced this issue Jan 3, 2025
co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
gaogaotiantian pushed a commit that referenced this issue Jan 10, 2025
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
gaogaotiantian pushed a commit to gaogaotiantian/cpython that referenced this issue Jan 13, 2025
…tions (pythonGH-128410)

(cherry picked from commit 1b39b50)

Co-authored-by: Adam Johnson <me@adamj.eu>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
gaogaotiantian added a commit that referenced this issue Jan 13, 2025
#128767)

* [3.13] gh-128409: Document that pdb.post_mortem() accepts exceptions (GH-128410)
(cherry picked from commit 1b39b50)

Co-authored-by: Adam Johnson <me@adamj.eu>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

1 participant