On Thu, Feb 12, 2015 at 11:01 PM, Guido van Rossum <gu...@python.org> wrote:

>
>> 2) always use the type of self when creating new instances
>>     ..
>>    cons:
>>      - if constructor signatures change, must override all methods which
>>        create new objects
>>
>
> Con for #2 is a showstopper. Forget about it.
>

Sorry if I am missing something obvious, but I still don't understand why
the same logic does not apply to class methods that create new instances:

>>> from datetime import *
>>> date.today()
datetime.date(2015, 2, 13)
>>> datetime.today()
datetime.datetime(2015, 2, 13, 11, 37, 23, 678680)
>>> class Date(date):
...     pass
...
>>> Date.today()
Date(2015, 2, 13)

(I actually find datetime.today() returning a datetime rather than a date a
questionable design decision, but probably the datetime type should not
have been a subclass of the date to begin with.)

Are there any date subclasses in the wild that don't accept year, month,
day in the constructor?  If you create such a class, wouldn't you want to
override __add__ and friends anyways?  We already know that you will have
to override today().
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to