[Python-Dev] subclassing builtin data structures

Alexander Belopolsky alexander.belopolsky at gmail.com
Fri Feb 13 19:02:41 CET 2015


On Fri, Feb 13, 2015 at 12:35 PM, Guido van Rossum <guido at python.org> wrote:

> IIUC you're proposing that the base class should *try* to construct an
> instance of the subclass by calling the type with an argument, and fail if
> it doesn't work. But that makes the whole thing brittle in the light of
> changes to the subclass constructor. Also, what should the argument be? The
> only answer I can think of is an instance of the base class.


No.  The arguments should be whatever arguments are appropriate for the
baseclass's __init__ or __new__.  In the case of datetime.date that would
be year, month, day.

Note that the original pure python prototype of the datetime module had
date.__add__ and friends call self.__class__(year, month, day).
Unfortunately, it looks like the original sandbox did not survive the the
hg conversion, so I cannot provide a link to the relevant history.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150213/ab2f66d5/attachment.html>


More information about the Python-Dev mailing list