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
>>>list.__bases__= (Iterator,)
Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>TypeError: can't set attributes of built-in/extension type 'list'
For simple static classes, which aren't supposed to have multiple bases (but sometimes do, e.g. numpy dtypes), this means swapping out tp_base, ensuring to test for tp_bases to handle multi-parent static or dynamic classes and to (throw NotImplementedError or) patch those instead.
We'd also want checks like type_set_bases has for circular inheritance, valid assignments, etc.
On the other hand, adding Py_TPFLAGS_HEAPTYPE to the PyTypeObject's tp_flags simply disables the rejection in check_set_special_type_attr. But compatible_for_assignment still rejects assigning list.__bases__ with new types, as newto->tp_free != oldto->tp_free, since PyBaseObject_Type->tp_free == PyObject_Del instead of PyObject_GC_Del. But object's lack of explicit GC support may not be an issue…
I need to monkeypatch the base class of builtin types. No fancy magic methods, I just need to inherit normal method like this (contrived example):
Naturally, this fails:
But forbiddenfruit also fails:
Could you please add this to
forbiddenfruit
?The text was updated successfully, but these errors were encountered: