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-99139: Improve NameError error suggestion for instances by pablogsal · Pull Request #99140 · python/cpython

Conversation

@pablogsal

@pablogsal pablogsal commented Nov 5, 2022 •
edited by bedevere-bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member
  • Issue: Improve NameError error suggestion for instances #99139

Sorry, something went wrong.

Uh oh!

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

AlexWaygood, pablogsal, ichard26, and JordanLevy99 reacted with heart emoji
All reactions
  • ❤️ 4 reactions
@pablogsal
pythongh-99139: Improve NameError error suggestion for instances
01650df
@pablogsal
pablogsal requested a review from iritkatriel as a code owner November 5, 2022 18:40
@bedevere-bot bedevere-bot mentioned this pull request Nov 5, 2022
Improve NameError error suggestion for instances #99139
Closed
@bedevere-bot bedevere-bot added the awaiting core review label Nov 5, 2022
@pablogsal
pablogsal requested review from ammaraskar and isidentical November 5, 2022 18:52
ammaraskar
ammaraskar approved these changes Nov 5, 2022
View reviewed changes

@ammaraskar ammaraskar left a comment

Copy link
Copy Markdown
Member

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.

Looks great :)

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/whatsnew/3.12.rst Resolved

Uh oh!

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

Comment thread Python/suggestions.c Resolved

Uh oh!

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

@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Nov 5, 2022
@pablogsal @ammaraskar
Update Doc/whatsnew/3.12.rst
b1546e5
Co-authored-by: Ammar Askar <[email protected]>
isidentical
isidentical reviewed Nov 5, 2022
View reviewed changes
Comment thread Python/suggestions.c Resolved

Uh oh!

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

isidentical
isidentical reviewed Nov 5, 2022
View reviewed changes
Comment thread Python/suggestions.c Resolved

Uh oh!

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

isidentical
isidentical approved these changes Nov 5, 2022
View reviewed changes

@isidentical isidentical left a comment

Copy link
Copy Markdown
Member

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.

Looks really helpful, thanks a lot @pablogsal!

Sorry, something went wrong.

Uh oh!

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

pablogsal reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@pablogsal pablogsal added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 5, 2022
@bedevere-bot

bedevere-bot commented Nov 5, 2022

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @pablogsal for commit b1546e5 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 5, 2022
pablogsal and others added 3 commits November 6, 2022 01:54
@pablogsal @ammaraskar
Update Python/suggestions.c
8a244b9
Co-authored-by: Ammar Askar <[email protected]>
@pablogsal @isidentical
Update Python/suggestions.c
d8933dd
Co-authored-by: Batuhan Taskaya <[email protected]>
@pablogsal @isidentical
Update Python/suggestions.c
4925719
Co-authored-by: Batuhan Taskaya <[email protected]>
@pablogsal pablogsal added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 6, 2022
@bedevere-bot

bedevere-bot commented Nov 6, 2022

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @pablogsal for commit 4925719 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 6, 2022
kumaraditya303
kumaraditya303 requested changes Nov 6, 2022
View reviewed changes
Comment thread Python/suggestions.c Resolved

Uh oh!

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

kumaraditya303
kumaraditya303 reviewed Nov 6, 2022
View reviewed changes
Comment thread Python/suggestions.c Resolved

Uh oh!

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

@pablogsal @kumaraditya303
Update Python/suggestions.c
ab2874a
Co-authored-by: Kumar Aditya <[email protected]>
kumaraditya303
kumaraditya303 reviewed Nov 6, 2022
View reviewed changes
Comment thread Python/suggestions.c Resolved

Uh oh!

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

kumaraditya303
kumaraditya303 reviewed Nov 6, 2022
View reviewed changes
Comment thread Python/suggestions.c Resolved

Uh oh!

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

@pablogsal
fixup! Update Python/suggestions.c
00706e4
@pablogsal
pablogsal merged commit 99e2e60 into python:main Nov 6, 2022
@pablogsal
pablogsal deleted the better_attr branch November 6, 2022 13:52
@bedevere-bot bedevere-bot removed the awaiting merge label Nov 6, 2022
serhiy-storchaka
serhiy-storchaka reviewed Jun 23, 2023
View reviewed changes
Comment thread Python/suggestions.c
if (!locals) {
goto error;
}
PyObject* self = PyDict_GetItem(locals, &_Py_ID(self)); /* borrowed */

@serhiy-storchaka serhiy-storchaka Jun 23, 2023

Copy link
Copy Markdown
Member

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.

Do not use PyDict_GetItem. It is broken by design.

Sorry, something went wrong.

Uh oh!

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

All reactions

@pablogsal pablogsal Jun 23, 2023

Copy link
Copy Markdown
Member 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.

What should we use instead for both?

Sorry, something went wrong.

Uh oh!

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

All reactions

@serhiy-storchaka serhiy-storchaka Jun 23, 2023

Copy link
Copy Markdown
Member

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.

PyDict_GetItemWithError and PyObject_GetAttr if limited by public API. It is suggested in the documentation. But _PyObject_LookupAttr is more convenient in the latter case.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Python/suggestions.c
goto error;
}

if (PyObject_HasAttr(self, name)) {

@serhiy-storchaka serhiy-storchaka Jun 23, 2023

Copy link
Copy Markdown
Member

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.

Do not use PyObject_HasAttr. It is broken by design.

Sorry, something went wrong.

Uh oh!

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

All reactions
@millerdev

millerdev commented Apr 10, 2025

Copy link
Copy Markdown

I'm surprised this uses hasattr under the covers. A simple benign name error could cause side effects at run time.

>>> class Test:
...     def __getattr__(self, name):
...         if name == "foo":
...             raise SystemExit("The end.")
...     def bar(self):
...         foo
... 
... Test().bar()
... 
The end.
All reactions

Sorry, something went wrong.

Uh oh!

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

@sobolevn sobolevn mentioned this pull request Apr 11, 2025
Instance attr error suggestions can execute __getattr__ #132385
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka left review comments
@kumaraditya303 kumaraditya303 kumaraditya303 requested changes
@ammaraskar ammaraskar ammaraskar approved these changes
@isidentical isidentical isidentical approved these changes
@iritkatriel iritkatriel Awaiting requested review from iritkatriel

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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.

7 participants

@pablogsal @bedevere-bot @millerdev @ammaraskar @serhiy-storchaka @isidentical @kumaraditya303
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 01402503 — 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.