-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
Description
Feature or enhancement
Proposal:
Looking at the hasattr(obj) source code I noticed it calls PyObject_GetOptionalAttr
Line 1244 in 9c1dfe2
| if (PyObject_GetOptionalAttr(obj, name, &v) < 0) { |
2 more things.
First inside of PyObject_GetOptionalAttr function PyUnicode_Check is called more than once (both at the start of the function, and in other functions later (like in _PyObject_GenericGetAttrWithDict)
Line 1188 in 9c1dfe2
| PyObject_GetOptionalAttr(PyObject *v, PyObject *name, PyObject **result) |
And second. Does the documentation for hasattr need improvement
Lines 1233 to 1235 in 9c1dfe2
| Return whether the object has an attribute with the given name. | |
| This is done by calling getattr(obj, name) and catching AttributeError. |
This issue report is made purely as possible performance improvement question, and should be treated like that, if it is something that shouldn't be done feel free to close the issue, otherwise I would gladly try to implement the proposed change
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response