On 05/07/2016 03:39 PM, Serhiy Storchaka wrote: > Some types have alternative constructors -- class methods used to create > an instance of the class. For example: int.from_bytes(), > float.fromhex(), dict.fromkeys(), Decimal.from_float(). > > But what should return these methods for subclasses? Should they return > an instance of base class or an instance of subclass? Almost all > alternative constructors return an instance of subclass (exceptions are > new in 3.6 bytes.fromhex() and bytearray.fromhex() that return bare > bytes and bytearray). But there is a problem, because this allows to > break invariants provided by the main constructor. Please ignore my comments in that issue. I actually prefer that class constructors go through the subclass' __new__ and __init__. Overriding parent class methods for the sole purpose of getting the subclass's type is quite irritating. -- ~Ethan~
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4