Bug or Feature?

Andrew Dalke adalke at mindspring.com
Mon Nov 24 21:56:50 EST 2003


Timothy C Delaney:
> > So what happens when I make a set subclass that takes no parameters
(other
> > than self) to   init  ?

David Eppstein:
> What do you expect to happen in general when you define a class that
> does not adhere to some protocol, and then use it in that protocol
> anyway?

It depends on what you deem to be "the protocol".  Things which
use the file protocol often only need the read or readline methods and
don't care about having flush or a given way to call the constructor.
The list protocol is usually only [] and __len__ or __iter__ and less
often get or setdefault or extend.

Going extreme the other way, the behaviour of the builtin
list is that type(x) is types.ListType, which is not true of any
other list-like object.

As for me personally, my answer to TCD is that sets.Set implements
the set protocol and a bit more, to make it useful for derived
classes.  I see the case he's talking about as outside the set
protocol and hence implementation defined.

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list