-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
voteThe WG is voting (or has voted)The WG is voting (or has voted)
Description
There is a private _PyType_Lookup() function which is used by 27 projects of the PyPI top 15,000 projects.
I propose to make the function public.
API: int PyType_Lookup(PyTypeObject *type, PyObject *name, PyObject **attr)
- Look for a type attribute through the type MRO. Do not invoke descriptors or metaclass
__getattr__(). - name must be a
str.- If found, set *attr to a strong reference and return
1. - If not found, set *attr to
NULLand return0. - On error, set an exception and return
-1.
- If found, set *attr to a strong reference and return
- Python pseudo-code (return
AttributeErrorif not found):
def PyType_Lookup(type, name):
if not isinstance(name, str):
raise TypeError
for klass in type.mro():
try:
return klass.__dict__[name]
except KeyError:
pass
# not found
return AttributeErrorThe private PyObject* _PyType_Lookup(PyTypeObject *type, PyObject *name) API returns a borrowed reference, whereas the proposed public API returns a strong reference, and it returns NULL if not found or on error, whereas the public API is not ambiguous (no need to check PyErr_Occurred()).
See:
Vote:
Metadata
Metadata
Assignees
Labels
voteThe WG is voting (or has voted)The WG is voting (or has voted)