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

traceback.print_last behaving differently across python versions #130250

Closed
mironleon opened this issue Feb 18, 2025 · 1 comment · Fixed by #130318
Closed

traceback.print_last behaving differently across python versions #130250

mironleon opened this issue Feb 18, 2025 · 1 comment · Fixed by #130318
Assignees
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error

Comments

@mironleon
Copy link

mironleon commented Feb 18, 2025

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

@mironleon mironleon added the type-bug An unexpected behavior, bug, or error label Feb 18, 2025
@serhiy-storchaka
Copy link
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

@serhiy-storchaka serhiy-storchaka added 3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Feb 18, 2025
@iritkatriel iritkatriel self-assigned this Feb 18, 2025
iritkatriel added a commit to iritkatriel/cpython that referenced this issue Feb 19, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 19, 2025
)

(cherry picked from commit 6c982ae)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 19, 2025
)

(cherry picked from commit 6c982ae)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
iritkatriel added a commit that referenced this issue Feb 19, 2025
…130326)

gh-130250: fix regression in traceback.print_last (GH-130318)
(cherry picked from commit 6c982ae)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
iritkatriel added a commit that referenced this issue Feb 19, 2025
…130325)

gh-130250: fix regression in traceback.print_last (GH-130318)
(cherry picked from commit 6c982ae)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
iritkatriel added a commit to iritkatriel/cpython that referenced this issue Feb 20, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 20, 2025
…H-130329)

(cherry picked from commit c718c6b)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 20, 2025
…H-130329)

(cherry picked from commit c718c6b)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
iritkatriel added a commit that referenced this issue Feb 20, 2025
) (#130331)

gh-130250: fix cleanup in test (impacts refleaks runs) (GH-130329)
(cherry picked from commit c718c6b)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
iritkatriel added a commit that referenced this issue Feb 20, 2025
) (#130330)

gh-130250: fix cleanup in test (impacts refleaks runs) (GH-130329)
(cherry picked from commit c718c6b)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
iritkatriel added a commit that referenced this issue Feb 20, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 20, 2025
…re beginning with a clean system state (pythonGH-130342)

(cherry picked from commit 048ee2d)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 20, 2025
…re beginning with a clean system state (pythonGH-130342)

(cherry picked from commit 048ee2d)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
iritkatriel added a commit that referenced this issue Feb 20, 2025
…'re beginning with a clean system state (GH-130342) (#130345)

gh-130250: use support.swap_attr() in test and don't assume we're beginning with a clean system state (GH-130342)
(cherry picked from commit 048ee2d)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
iritkatriel added a commit that referenced this issue Feb 20, 2025
…'re beginning with a clean system state (GH-130342) (#130344)

gh-130250: use support.swap_attr() in test and don't assume we're beginning with a clean system state (GH-130342)
(cherry picked from commit 048ee2d)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants