Skip to content

gh-135511 Fixed NameError and AttributeError lack of the message in IDLE#135526

Open
Locked-chess-official wants to merge 9 commits into
python:mainfrom
Locked-chess-official:main
Open

gh-135511 Fixed NameError and AttributeError lack of the message in IDLE#135526
Locked-chess-official wants to merge 9 commits into
python:mainfrom
Locked-chess-official:main

Conversation

@Locked-chess-official

@Locked-chess-official Locked-chess-official commented Jun 15, 2025

Copy link
Copy Markdown
Contributor

@python-cla-bot

python-cla-bot Bot commented Jun 15, 2025

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

bedevere-app Bot commented Jun 15, 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.

@Locked-chess-official Locked-chess-official changed the title Fixed NameError and AttributeError lack of the message in IDLE gh-135511 Fixed NameError and AttributeError lack of the message in IDLE Jun 15, 2025
@Locked-chess-official

Copy link
Copy Markdown
Contributor Author

I use blurb to create a .rst file then click add file and choose it to IDLE, but it was wrong. So how should I do?

@terryjreedy terryjreedy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To add a test, I think if might be sufficient to add the following tuple to the end of data in test_idle.test_run.ExceptionTest.

            ('raise NameError("123\n456")', NameError, "123\n456\n"),

If you want me to make changes and test, I will, but I need sleep now.

Comment thread Lib/idlelib/run.py Outdated
Comment thread Misc/NEWS.d/next/IDLE/2025-06-15-09-50-19.gh-issue-135511.2C5EX-.rst Outdated
Comment thread Lib/idlelib/run.py Outdated
@bedevere-app

bedevere-app Bot commented Jun 15, 2025

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Comment thread Lib/idlelib/run.py Outdated
@terryjreedy

Copy link
Copy Markdown
Member

The hint process is rather fragile. Modifying get_message_lines so that sys.excepthook does not print any traceback, which require setting err.traceback to None before the call in addition to not passing a traceback, can alter the hint. In particular, for abc, "Did you mean: 'abs'?" is omitted and only "Did you forget to import 'abc'?" is added. Not only do the message changes break multiple tests, but this particular result is worse for the user. I am accepting the alternative of directly printing multiline user name error messages instead of calling a modified get_message_lines. I will look at adding a new test_xxx function to test the case fixed here.

@Locked-chess-official

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again

@bedevere-app

bedevere-app Bot commented Jun 16, 2025

Copy link
Copy Markdown

Thanks for making the requested changes!

@terryjreedy: please review the changes made to this pull request.

@bedevere-app bedevere-app Bot requested a review from terryjreedy June 16, 2025 01:03
@Locked-chess-official

Copy link
Copy Markdown
Contributor Author

@terryjreedy

@Locked-chess-official

Copy link
Copy Markdown
Contributor Author

To add the test, I have to add a new default for print_exception(), now is print_exception(in_test=False). When in test, nothing will be print to sys.stderr. It is for test_run.py. In test_run.py, it needs to change the test to exec mode and use another way to test.

@Locked-chess-official

Copy link
Copy Markdown
Contributor Author

I make the change clearer now.

Comment thread Lib/idlelib/run.py Outdated
@github-actions

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 Apr 26, 2026
Refactor exception message handling to use TracebackException.
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jun 22, 2026
@Locked-chess-official

Copy link
Copy Markdown
Contributor Author

@serhiy-storchaka
@terryjreedy
@picnixz
I found that traceback.TracebackException.format_exception_only can fix this problem.

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.

2 participants