Differences creating tuples and collections.namedtuples
greg.ewing at canterbury.ac.nz
Tue Feb 19 08:54:49 CET 2013
Steven D'Aprano wrote:
> Terry Reedy wrote:
>>In fact, one reason to subclass a class is to change the initialization
> That might be a reason that people give, but it's a bad reason from the
> perspective of interface contracts, duck-typing and the LSP.
Only if you're going to pass the class off to something as
a factory function.
Note that having a different constructor signature is *not*
an LSP violation for *instances* of a class. The constructor
is not part of the interface for instances, only for the
In practice, it's very common for a class to have a different
constructor signature from its base class, and this rarely
causes any problem.
IPython is simply making a dodgy assumption. It gets away with
it only because it's very rare to encounter subclasses of
list or tuple at all.
More information about the Python-list