def patchable_builtin(klass):
# It's important to create variables here, we want those objects alive
# within this whole scope.
name = klass.__name__
target = klass.__dict__
# Hardcore introspection to find the `PyProxyDict` object that contains the
# precious `dict` attribute.
proxy_dict = SlotsProxy.from_address(id(target))
namespace = {}
# This is the way I found to `cast` this `proxy_dict.dict` into a python
# object, cause the `from_address()` function returns the `py_object`
# version
ctypes.pythonapi.PyDict_SetItem(
ctypes.py_object(namespace),
ctypes.py_object(name),
proxy_dict.dict,
)
return namespace[name]
评论列表
文章目录