It seems to me that the utility of subclassing certain library classes would be increased if the user could set a factory that the base class would use when creating new instances. That way, from the user's point of view, functionality would not "disappear" after operations e.g. class MyDate(datetime.date): def foo(self): ... nextday = MyDate(...) + datetime.timedelta(days=1) nextday.foo() # exception Storing the factory information in the base class has the disadvantage of causing a global behavior change but can probably be made speed efficient. Storing the factory in the subclass would require that the super class check for a class variable when creating instances. It would probably provide the most obvious semantics from the programmer's POV but would be organizationally odd i.e. each class would have to provide a factory for every overriden type that it's superclass creates. Aside from datime.* this feature seems like it would be useful for other types where there is potential for making useful subclasses (unlike int) and where many operations result in new instances. sets come to mind. Any thoughts? Cheers, Brian
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