Looking for a list subclassing example...
Kragen Sitaker
kragen at pobox.com
Mon Jun 10 08:05:42 EDT 2002
Erik Max Francis <max at alcyone.com> writes:
> Kragen Sitaker wrote:
> > Why do you think it's a good idea to subclass 'list'?
> >
> > I don't have one to show, but I think it's generally not a good idea.
>
> Why do you think it was made possible in 2.2, then?
As an experiment. In October, Guido said:
Subclassing list and dictionary etc. should be seen as an experimental
feature; I don't want to fully fix the semantics yet in all cases.
. . .
Subclassing a built-in type is appropriate when either (a) you want to
use it in a context where a genuine list/dictionary/file/etc.; or (b)
you want the speed advantage of the built-in type. In both cases you
have to live with some restrictions. Remapping the fundamental
accessors (like __getitem__) is probably not a good idea in either
case. Adding new state and behavior is fine.
[from
<http://groups.google.com/groups?selm=mailman.1004342434.4625.python-list%40python.org>]
I'm tempted to be flippant and say "to confuse new users" or "as a
sick joke", but as Guido points out, there are at least two valid
reasons to do it: to optimize your code and to work around breakage
--- well, let's say inconsistent, inflexible behavior --- caused by
other people's optimizations.
More information about the Python-list
mailing list