GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-129605: Add more exception handling when computing suggestions in traceback.py by ADThomas-astro · Pull Request #129632 · python/cpython

Conversation

@ADThomas-astro

@ADThomas-astro ADThomas-astro commented Feb 4, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

In _compute_suggestion_error in traceback.py, the code that handles AttributeError and ImportError is wrapped in try-excepts, but the code for NameError is not wrapped in a try-except. However, the hasattr(self, wrong_name) call fails if accessing an attribute raises an exception. This is what happens in the reproducer in the issue.

I wrapped the handling of NameError in a try-except to match the handling of the other two exception types.

I also added three related tests to test_traceback.py. All three of the new tests crash both PyREPL and the test_traceback.py test suite without the fix. The property test needed some creativity to trigger the bug and I'm a bit proud of it 😛

Let me know if the tests also need to be added to the PyREPL test suite.

  • Issue: traceback._compute_suggestion_error crashes on __getattr__ raising #129605

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

danielhollas reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@ghost

ghost commented Feb 4, 2025 •
edited by ghost
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

bedevere-app Bot commented Feb 4, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added the awaiting review label Feb 4, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Feb 4, 2025
traceback._compute_suggestion_error crashes on __getattr__ raising #129605
Closed
danielhollas
danielhollas reviewed Feb 4, 2025
View reviewed changes
Comment thread Lib/traceback.py
assert isinstance(exc_value, NameError)
# find most recent frame
if tb is None:
try:

@danielhollas danielhollas Feb 4, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very broad try-except block. If you scoped it only around the hasattr call would the new test cases still pass?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ZeroIntensity and picnixz reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

@ADThomas-astro ADThomas-astro Feb 5, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes they would still pass. It's usually good practice to minimise code in a try block, but I think this is an exceptional case. This function attempts to provide "Did you mean foo?" suggestions after there has already been an error in user code. Hence a different exception propagating from this function is very unhelpful (and the cause of the issue). So I think it's worth having wider try blocks here to minimise the risk of unhandled exceptions in the future. The existing code has wide try blocks ignoring all Exception subclasses when doing processing for AttributeError (L1485-1494) and ImportError (L1499-1502). I think we we should treat the processing for NameError the same. (Although - I haven't found a way to cause an exception in L1508-1517, so this is mostly theoretical.) Happy to narrow the scope of the try if folks feel strongly.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions

github-actions Bot commented Apr 21, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 21, 2026
ADThomas-astro and others added 2 commits October 20, 2026 23:02
@ADThomas-astro @ambv
Add fix and tests
e93095c
@blurb-it @ambv
📜🤖 Added by blurb_it.
97771ba
@ambv
ambv force-pushed the gh129605_fix branch from 617c0b0 to 97771ba Compare October 20, 2026 21:03
@ambv ambv added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 20, 2026
@ambv
ambv merged commit 97b5f24 into python:main Oct 20, 2026
57 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app

miss-islington-app Bot commented Oct 20, 2026

Copy link
Copy Markdown

Thanks @ADThomas-astro for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting review label Oct 20, 2026
@miss-islington-app

miss-islington-app Bot commented Oct 20, 2026

Copy link
Copy Markdown

Sorry, @ADThomas-astro and @ambv, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 97b5f245136eb91bbc1aeddfcbf9bc571cedfdb5 3.14
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

bedevere-app Bot commented Oct 20, 2026

Copy link
Copy Markdown

GH-159983 is a backport of this pull request to the 3.15 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app miss-islington-app Bot assigned ambv Oct 20, 2026
@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 20, 2026
@bedevere-bot

bedevere-bot commented Oct 20, 2026

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot x86 Debian Installed with X 3.x (tierless) has failed when building commit 97b5f24.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1244/builds/9980) and take a look at the build logs.
  4. Check if the failure is related to this commit (97b5f24) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1244/builds/9980

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/contextlib.py"�[0m, line �[35m116�[0m, in �[35minner�[0m
    return func(*args, **kwds)
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/test/_test_multiprocessing.py"�[0m, line �[35m651�[0m, in �[35mtest_interrupt�[0m
    exitcode = self._kill_process(multiprocessing.Process.interrupt)
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/contextlib.py"�[0m, line �[35m116�[0m, in �[35minner�[0m
    return func(*args, **kwds)
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/test/_test_multiprocessing.py"�[0m, line �[35m632�[0m, in �[35m_kill_process�[0m
    self.assertEqual(�[31mjoin�[0m�[1;31m()�[0m, None)
                     �[31m~~~~�[0m�[1;31m^^�[0m
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/test/_test_multiprocessing.py"�[0m, line �[35m305�[0m, in �[35m__call__�[0m
    return �[31mself.func�[0m�[1;31m(*args, **kwds)�[0m
           �[31m~~~~~~~~~�[0m�[1;31m^^^^^^^^^^^^^^^�[0m
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/multiprocessing/process.py"�[0m, line �[35m156�[0m, in �[35mjoin�[0m
    res = self._popen.wait(timeout)
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/multiprocessing/popen_fork.py"�[0m, line �[35m44�[0m, in �[35mwait�[0m
    return �[31mself.poll�[0m�[1;31m(os.WNOHANG if timeout == 0.0 else 0)�[0m
           �[31m~~~~~~~~~�[0m�[1;31m^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^�[0m
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/multiprocessing/popen_fork.py"�[0m, line �[35m28�[0m, in �[35mpoll�[0m
    pid, sts = �[31mos.waitpid�[0m�[1;31m(self.pid, flag)�[0m
               �[31m~~~~~~~~~~�[0m�[1;31m^^^^^^^^^^^^^^^^�[0m
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/test/_test_multiprocessing.py"�[0m, line �[35m628�[0m, in �[35mhandler�[0m
    raise RuntimeError('join took too long: %s' % p)
�[1;35mRuntimeError�[0m: �[35mjoin took too long: <Process name='Process-1' pid=3159 parent=3157 started daemon>�[0m


Traceback (most recent call last):
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/contextlib.py"�[0m, line �[35m116�[0m, in �[35minner�[0m
    return func(*args, **kwds)
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/test/_test_multiprocessing.py"�[0m, line �[35m651�[0m, in �[35mtest_interrupt�[0m
    exitcode = self._kill_process(multiprocessing.Process.interrupt)
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/contextlib.py"�[0m, line �[35m116�[0m, in �[35minner�[0m
    return func(*args, **kwds)
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/test/_test_multiprocessing.py"�[0m, line �[35m632�[0m, in �[35m_kill_process�[0m
    self.assertEqual(�[31mjoin�[0m�[1;31m()�[0m, None)
                     �[31m~~~~�[0m�[1;31m^^�[0m
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/test/_test_multiprocessing.py"�[0m, line �[35m305�[0m, in �[35m__call__�[0m
    return �[31mself.func�[0m�[1;31m(*args, **kwds)�[0m
           �[31m~~~~~~~~~�[0m�[1;31m^^^^^^^^^^^^^^^�[0m
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/multiprocessing/process.py"�[0m, line �[35m156�[0m, in �[35mjoin�[0m
    res = self._popen.wait(timeout)
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/multiprocessing/popen_fork.py"�[0m, line �[35m44�[0m, in �[35mwait�[0m
    return �[31mself.poll�[0m�[1;31m(os.WNOHANG if timeout == 0.0 else 0)�[0m
           �[31m~~~~~~~~~�[0m�[1;31m^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^�[0m
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/multiprocessing/popen_fork.py"�[0m, line �[35m28�[0m, in �[35mpoll�[0m
    pid, sts = �[31mos.waitpid�[0m�[1;31m(self.pid, flag)�[0m
               �[31m~~~~~~~~~~�[0m�[1;31m^^^^^^^^^^^^^^^^�[0m
  File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/test/_test_multiprocessing.py"�[0m, line �[35m628�[0m, in �[35mhandler�[0m
    raise RuntimeError('join took too long: %s' % p)
�[1;35mRuntimeError�[0m: �[35mjoin took too long: <Process name='Process-170' pid=16764 parent=14673 started daemon>�[0m
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv ambv mentioned this pull request Oct 20, 2026
[3.14] gh-129605: Add more exception handling when computing suggestions in traceback.py (GH-129632) #159994
Merged
@bedevere-app

bedevere-app Bot commented Oct 20, 2026

Copy link
Copy Markdown

GH-159994 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 20, 2026
@ambv

ambv commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Pretty sure this PR is innocent of the "x86 Debian Installed with X 3.x" failure. Same commit, same machine, passed on "x86 Debian Non-Debug with X 3.x", build 9835 on the same worker (ware-debian-x86). It built the same 97b5f24 commit starting at 23:22:52 UTC, one second after the failing build finished. It passed, including test_multiprocessing_fork.test_processes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ambv pushed a commit that referenced this pull request Oct 21, 2026
@miss-islington @ADThomas-astro
[3.15] gh-129605: Add more exception handling when computing suggesti…
9ce74c5
…ons in traceback.py (GH-129632) (#159983)

(cherry picked from commit 97b5f24)

Co-authored-by: Adam D. Thomas <[email protected]>
ambv added a commit that referenced this pull request Oct 21, 2026
@ambv @ADThomas-astro
[3.14] gh-129605: Add more exception handling when computing suggesti…
a14a97f
…ons in traceback.py (GH-129632) (#159994)

(cherry picked from commit 97b5f24)

Co-authored-by: Muse Code (Meta Muse Spark)
Co-authored-by: Adam D. Thomas <[email protected]>
@ambv ambv mentioned this pull request Oct 23, 2026
gh-129605: Fix crashing pyrepl when NameError occurres in __getattr__ method #129615
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@danielhollas danielhollas danielhollas left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@ambv ambv

Labels

stale Stale PR or inactive for long period of time.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@ADThomas-astro @bedevere-bot @ambv @danielhollas
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.