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 _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/TOBBYPYOYBJV2FBC6PQFKZMNK46JCT3Y/ Code of Conduct: http://python.org/psf/codeofconduct/