Bug or Feature?

Stephan Diehl stephan.diehlNOSPAM at gmx.net
Mon Nov 24 20:33:33 CET 2003

Tim Peters wrote:

> So the implementation strives never to screw you, but it may not do what
> you
> want, either.  If you want Ints to be closed under an operation, you need
> to supply an appropriate implementation of that operation as a method of
> Int. Then you control the optimizations you're willing to accept, and can
> construct your Int instances so as to satisfy Int invariants (something
> the base class can't know how to do, since it can't have any idea of what
> user-defined invariants may be -- although it's hard to see the point to
> this in the Int example as given, because the Int class is trivial).

Sounds very reasonable. The triviality of the Int example was the reason I
had expected differently (and the fact that int,str,... are immutable what
let them stand out somehow)

>> by contrast:
>> >>> class myset(Set):pass
>> ...
>> >>> a = myset([1,2])
>> >>> b = myset([2,3])
>> >>> c = a & b
>> >>> type(c)
>> <class '__main__.myset'>
>> subclasses of Set are closed under the set operations. :-)
> If you let Guido see that, it won't in 2.4 <wink>.

Could we please delete this thread? What have I done?

More information about the Python-list mailing list