[Python-Dev] subclassing builtin data structures

Guido van Rossum guido at python.org
Fri Feb 13 18:35:15 CET 2015


On Thu, Feb 12, 2015 at 8:58 PM, Ethan Furman <ethan at stoneleaf.us> wrote:

> On 02/12/2015 08:01 PM, Guido van Rossum wrote:
> > On Thu, Feb 12, 2015 at 7:41 PM, Ethan Furman 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.
>
> Happy to, but can you explain why requiring the programmer to override the
> necessary methods, or get tracebacks, is a
> showstopper?  Is there a previous email thread I can read that discusses
> it?
>

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. Finally, this
would require more special-casing in every built-in class (at least every
built-in class that sometimes returns instances of itself).

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150213/a9765340/attachment.html>


More information about the Python-Dev mailing list