You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
assignee=Noneclosed_at=<Date2018-12-11.13:14:34.224>created_at=<Date2018-12-09.11:01:30.721>labels= ['interpreter-core', '3.7', '3.8']
title='Unify and optimize the helper for getting a builtin object'updated_at=<Date2018-12-11.13:14:34.223>user='https://github.com/serhiy-storchaka'
_PyIter_GetBuiltin() was introduced in bpo-14288 (31668b8). This was used for getting references to the builtin "iter" and "reverse". It was renamed to _PyObject_GetBuiltin() in a701388.
There is other code that gets references to the builtin "getattr" using PyEval_GetBuiltins(). It is more efficient, but contains bugs.
The proposed PR unifies getting references to builtins:
The prefix _PyObject_ is changed to _PyEval_, since this function has relation not to the object type but to the evaluation environment.
It uses now the private _Py_Identifier API instead of a raw C string. This saves time by omitting the creation of a Unicode object on every call.
It uses now fast PyEval_GetBuiltins() instead of slower PyImport_Import().
Fixed errors handling in the code that used PyEval_GetBuiltins() before. It no longer swallows unexpected exceptions, no longer returns an error without setting an exception, and no longer causes raising a SystemError.
An example of an error in current code:
>>> import builtins
>>> del builtins.getattr
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError: NULL object passed to Py_BuildValue