[Python-Dev] subclassing builtin data structures (original) (raw)
Mark Roberts wizzat at gmail.com
Fri Feb 13 03:59:32 CET 2015
- Previous message: [Python-Dev] subclassing builtin data structures
- Next message: [Python-Dev] subclassing builtin data structures
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Feb 12, 2015, at 18:40, Chris Angelico <rosuav at gmail.com> wrote:
On Fri, Feb 13, 2015 at 12:46 PM, MRAB <python at mrabarnett.plus.com> wrote:
class BaseInt: ... def init(self, value): ... self.value = value ... def add(self, other): ... return type(self)(self.value + other) On Fri, Feb 13, 2015 at 11:55 AM, Guido van Rossum <guido at python.org> wrote: ... there is no reason (in general) why the signature of a subclass constructor should match the base class constructor, and it often doesn't. You're requiring that any subclass of BaseInt be instantiable with one argument, namely its value. That's requiring that the signature of the subclass constructor match the base class constructor. ChrisA
Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/wizzat%40gmail.com
No, it seems like he's asking that the type return a new object of the same type instead of one of the superclass. In effect, making the Date class call type(self)(*args) instead of datetime.date(*args). He seems completely willing to accept the consequences of changing the constructor (namely that he will have to override all the methods that call the constructor).
It seems like good object oriented design to me.
-Mark
- Previous message: [Python-Dev] subclassing builtin data structures
- Next message: [Python-Dev] subclassing builtin data structures
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]