← 输入框|github.com|刷新
Skip to content

traceback.print_last behaving differently across python versions #130250

Closed

Description

@mironleon

Bug report

Bug description:

traceback.print_last() correctly prints the latest traceback for python 3.10.16 and 3.11.9, but it prints NoneType: None for 3.12.9 and 3.13.2

See also ipython/ipython#14744, I originally thought it was an ipython issue

Python 3.10.16 (main, Feb 13 2025, 14:32:36) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
>>> import traceback
>>> traceback.print_last()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
Python 3.11.9 (main, Feb 13 2025, 14:34:41) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
>>> import traceback
>>> traceback.print_last()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
Python 3.12.9 (main, Feb 13 2025, 13:23:03) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
>>> import traceback
>>> traceback.print_last()
NoneType: None
Python 3.13.2 (main, Feb 13 2025, 11:10:27) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/0
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    1/0
    ~^~
ZeroDivisionError: division by zero
>>> import traceback
>>> traceback.print_last()
NoneType: None

CPython versions tested on:

3.10, 3.11, 3.12, 3.13

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    type-bug
    on Feb 18, 2025
  2. serhiy-storchaka commented on Feb 18, 2025

    @serhiy-storchaka
    Member

    If you remove sys.last_exc, you will get the old behavior.

    >>> import sys
    >>> sys.last_exc
    ZeroDivisionError('division by zero')
    >>> del sys.last_exc
    >>> traceback.print_last()
    Traceback (most recent call last):
      File "<python-input-0>", line 1, in <module>
        1/0
        ~^~
    ZeroDivisionError: division by zero

    The regression was most likely introduced in #102778. cc @iritkatriel

  3. added
    3.12
    3.13
    3.14
    on Feb 18, 2025
  4. self-assigned this
    on Feb 18, 2025
  5. added 2 commits that reference this issue on Feb 19, 2025
  6. added 2 commits that reference this issue on Feb 19, 2025
  7. added 4 commits that reference this issue on Feb 19, 2025
  8. added 2 commits that reference this issue on Feb 20, 2025
  9. added 3 commits that reference this issue on Feb 20, 2025
  10. added 2 commits that reference this issue on Feb 20, 2025
  11. added 2 commits that reference this issue on Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.123.133.14type-bug

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions