gh-99139: Improve NameError error suggestion for instances#99140
gh-99139: Improve NameError error suggestion for instances#99140pablogsal merged 7 commits intopython:mainfrom
Conversation
Co-authored-by: Ammar Askar <[email protected]>
isidentical
left a comment
There was a problem hiding this comment.
Looks really helpful, thanks a lot @pablogsal!
|
🤖 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. |
Co-authored-by: Ammar Askar <[email protected]>
Co-authored-by: Batuhan Taskaya <[email protected]>
Co-authored-by: Batuhan Taskaya <[email protected]>
|
🤖 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. |
Co-authored-by: Kumar Aditya <[email protected]>
| if (!locals) { | ||
| goto error; | ||
| } | ||
| PyObject* self = PyDict_GetItem(locals, &_Py_ID(self)); /* borrowed */ |
There was a problem hiding this comment.
Do not use PyDict_GetItem. It is broken by design.
There was a problem hiding this comment.
What should we use instead for both?
There was a problem hiding this comment.
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.
| goto error; | ||
| } | ||
|
|
||
| if (PyObject_HasAttr(self, name)) { |
There was a problem hiding this comment.
Do not use PyObject_HasAttr. It is broken by design.
|
I'm surprised this uses >>> class Test:
... def __getattr__(self, name):
... if name == "foo":
... raise SystemExit("The end.")
... def bar(self):
... foo
...
... Test().bar()
...
The end. |
Uh oh!
There was an error while loading. Please reload this page.