-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-106521: Add PyObject_GetOptionalAttr() function #106522
gh-106521: Add PyObject_GetOptionalAttr() function #106522
Conversation
It is a new name of former _PyObject_LookupAttr().
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.
To ease the review, you might keep the old name with an alias #define _PyObject_LookupAttr PyObject_GetOptionalAttr
, and then write a second PR to update usage of the old name. (Well, just split the PR in two parts.)
|
||
|
||
.. c:function:: int PyObject_GetOptionalAttrString(PyObject *obj, const char *attr_name, PyObject **result); | ||
|
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.
You may just say:
Similar to :c:func:`PyObject_GetOptionalAttr`, but *name* is a UTF-8 encoded string.
To not copy/paste the documentation.
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.
In all other functions with String
suffix the documentation is repeated. If we are going to change this, it should be changed for all function at once.
Co-authored-by: Victor Stinner <[email protected]>
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.
LGTM. Thanks for the update.
`_PyObject_LookupAttrId` was removed / replaced with `PyObject_GetOptionalAttrString` in python/cpython#106522. https://docs.python.org/dev/c-api/object.html#c.PyObject_GetOptionalAttrString Fixes ```cpp /home/runner/work/mypy/mypy/mypyc/lib-rt/pythonsupport.h: In function ‘update_bases’: (diff) /home/runner/work/mypy/mypy/mypyc/lib-rt/pythonsupport.h:51:13: error: implicit declaration of function ‘_PyObject_LookupAttrId’; did you mean ‘_PyObject_GetAttrId’? [-Werror=implicit-function-declaration] (diff) 51 | if (_PyObject_LookupAttrId(base, &PyId___mro_entries__, &meth) < 0) { (diff) | ^~~~~~~~~~~~~~~~~~~~~~ (diff) | _PyObject_GetAttrId (diff) ```
It is a new name of former _PyObject_LookupAttr().
📚 Documentation preview 📚: https://cpython-previews--106522.org.readthedocs.build/