[Python-Dev] subclassing builtin data structures

Jonas Wielicki jonas at wielicki.name
Fri Feb 13 09:41:57 CET 2015


If I may humbly chime in this, with a hint...

On 13.02.2015 05:01, Guido van Rossum wrote:
> On Thu, Feb 12, 2015 at 7:41 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
>> [snip]
>> 2) always use the type of self when creating new instances
>>
>>    pros:
>>      - subclasses automatically maintain type
>>      - much less code in the simple cases [1]
>>
>>    cons:
>>      - if constructor signatures change, must override all methods which
>>        create new objects
>>
>> Unless there are powerful reasons against number 2 (such as performance,
>> or the effort to affect the change), it sure
>> seems like the nicer way to go.
>>
>> So back to my original question: what other concerns are there, and has
>> anybody done any benchmarks?
>>
> 
> Con for #2 is a showstopper. Forget about it.

I would like to mention that there is another language out there which
knows about virtual constructors (virtual like in virtual methods, with
signature match requirements and such), which is FreePascal (and Delphi,
and I think original Object Pascal too).

It is actually a feature I liked about these languages, compared to
C++03 and others, that constructors could be virtual and that classes
were first-class citizens.

Of course, Python cannot check the signature at compile time. But I
think as long as it is documented, there should be no reason not to
allow and support it. It really is analogous to other methods which need
to have a matching signature.

just my two cents,
jwi


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150213/f0a82b01/attachment.sig>


More information about the Python-Dev mailing list