[issue32571] Speed up and clean up getting optional attributes in C code
Nathaniel Smith
report at bugs.python.org
Wed Jan 17 06:32:31 EST 2018
Nathaniel Smith <njs at pobox.com> added the comment:
Can I ask why this is a private API? It's extremely useful for extension modules too. For example, numpy has been carrying around a reimplementation of PyObject_GetAttr for years, exactly to avoid the cost of creating an AttributeError exception in common cases:
https://github.com/numpy/numpy/blob/master/numpy/core/src/private/get_attr_string.h
(To emphasize the similarity, note that the code above used to be called PyArray_GetAttrString_SuppressException, until a refactoring last year: https://github.com/numpy/numpy/commit/69a423b23492ecf8471efc4e59ab8a93b03d8454. It's always been specifically used for looking up numpy-specific special methods like __array__, __array_interface__, etc., though, which is why it can get away with those shortcuts -- we know they usually aren't defined.)
----------
nosy: +njs
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32571>
_______________________________________
More information about the Python-bugs-list
mailing list