[Python-Dev] Return type of alternative constructors (original) (raw)

Guido van Rossum guido at python.org
Sun May 8 03:03:45 EDT 2016


IMO bool is a special case because it's meant to be a final class, and the implementation of int (which is in C and so can violate most rules) doesn't respect that.

But in general I think the only reasonable approach is that a construction class method should return an instance of the subclass; these class methods have a signature that's constrained by their signature in the base class.

OTOH operators like add cannot be expected to return an instance of the subclass, because these typically construct an instance using new/init, whose signatures are not constrained by the base class. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160508/52474383/attachment.html>



More information about the Python-Dev mailing list