On 09May2019 2120, Hugh Fisher wrote:
This is related I think to Victor's work on the levels of C API compatibility. Is there a requirement that a subclass of a builtin type must implement the entire C API?
It's not related to the compatibility work, but a subclass of a builtin type *is* the builtin type with some Python attributes/methods added. Otherwise it won't report as being a subclass (both *_Check and *_CheckExact will fail).
What you lose by using the concrete API is the ability to use those Python methods. For example, given:
class MyDict(dict): def __getitem__(self, key): return super()[key.lower()]
Calling this with PyObject_GetItem(...) will resolve the Python __getitem__ and call it. However, using PyDict_GetItem(...) will not, as it goes directly to the C structure (because it's actually the default implementation of dict.__getitem__, so it "should" only be called when it has not been overridden, and therefore does not have to check for overrides).
So if you have a subclass with the same semantics for core operations, it'll be fine. But if the caller is expecting that subclass to behave differently based on overrides, it won't.