Bug or Feature?

Mel Wilson mwilson at the-wire.com
Tue Nov 25 12:53:23 EST 2003


In article <Sxzwb.12921$sb4.952 at newsread2.news.pas.earthlink.net>,
"Andrew Dalke" <adalke at mindspring.com> wrote:
>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.

   Files are mutable, and most file methods change the
object in-place.  There's no question of creating a
different file, modified.  Looks like there's more
difference between mutable and immutable class instances
than just __new__.

   It's nice to respect a descendant's choice of __init__,
but if you blow off all the descendant's own methods as a
consequence, it's not so nice.

>[ ... ]
>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.

   I think behaviour of __init__ is just one more class
characteristic to be documented.

        Regards.        Mel.




More information about the Python-list mailing list