Skip to content

gh-153374: Better way to clear name error suggestion#141389

Open
Locked-chess-official wants to merge 12 commits into
python:mainfrom
Locked-chess-official:clear_NameError_suggestion
Open

gh-153374: Better way to clear name error suggestion#141389
Locked-chess-official wants to merge 12 commits into
python:mainfrom
Locked-chess-official:clear_NameError_suggestion

Conversation

@Locked-chess-official

@Locked-chess-official Locked-chess-official commented Nov 11, 2025

Copy link
Copy Markdown
Contributor

Thanks blhsing. This way don't need to change the C code.

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

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

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 2, 2026
@sergey-miryanov

Copy link
Copy Markdown
Contributor

I propose you to open a new issue if you want to continue work on this.

@StanFromIreland

Copy link
Copy Markdown
Member

Yes this needs a new issue, closing for now.

@Locked-chess-official Locked-chess-official changed the title gh-138890: Better way to clear name error suggestion gh-153374: Better way to clear name error suggestion Jul 9, 2026
@Locked-chess-official

Copy link
Copy Markdown
Contributor Author

@StanFromIreland new issue is ready

Comment thread Lib/traceback.py Outdated
@brijkapadia

Copy link
Copy Markdown
Contributor

You should also probably add a regression test in case the bytecode changes again or something similar happens

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jul 10, 2026
Comment thread Lib/test/test_traceback.py Outdated

def test_name_error_do_not_suggest_builtin_name_in_delete(self):
def func():
del next

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this.

Since del next is inside a function, this raises an UnboundLocalError, not a NameError. However, your change only applies to a NameError.

In order to write an appropriate test, you need to run del next in the global scope. My guess is that you'll need to use an exec.

actual = self.get_suggestion(func)
self.assertNotIn("Did you mean: 'anext'", actual)

def test_name_error_suggest_builtin_name_in_delete_if_not_delete_the_name_itself(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if these are necessary

@brijkapadia

Copy link
Copy Markdown
Contributor

You don't need to keep updating the branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants