
On Mon, Dec 19, 2022 at 05:53:38PM -0800, Ethan Furman wrote:
Personally, every other time I've wanted to subclass a built-in data type, I've wanted the built-in methods to return my subclass, not the original class.
Enums are special. But outside of enums, I cannot think of any useful situation where the desirable behaviour is for methods on a subclass to generally return a superclass rather than the type of self. Its normal behaviour for operations on a class K to return K instances, not some superclass of K. I dare say there are a few, but they don't come to mind.
All of which is to say: sometimes you want it one way, sometimes the other. ;-)
Yes, but one way is *overwhelmingly* more common than the other. Builtins make the rare form easy and the common form hard.
Metaclasses, anyone?
Oh gods, we shouldn't need to write a metaclass just to get methods that create instances of the calling class instead of one of its superclasses. -- Steve