explain this: Is it a good idea to implement subclasshook in our own ABCs? Probably not.…
- User
explain this: Is it a good idea to implement subclasshook in our own ABCs? Probably not. All the implementations of subclasshook I’ve seen in the Python source code are in ABCs like Sized that declare just one special method, and they simply check for that special method name. Given their “special” status, you can be pretty sure that any method named len does what you expect. But even in the realm of special methods and fundamental ABCs, it can be risky to make such assumptions. For example, mappings implement len, getitem, and iter, but they are rightly not considered subtypes of Sequence, because you can’t retrieve items using integer offsets or slices. That’s why the abc.Sequence class does not implement subclasshook.
- Assistant