2.2 features

Quinn Dunkan quinn at retch.ugcs.caltech.edu
Sat Jul 28 14:33:33 EDT 2001


On Sat, 28 Jul 2001 02:02:40 GMT, Guido van Rossum <guido at python.org> wrote:
>Kirill Simonov <kirill at xyz.donetsk.ua> writes:
>
>> It would be nice to have 'in' operator for types:
>> 
>> assert (num in int)
>> assert (msg in str)

This implies (at least to me) that 'in' would be a general shorthand for
'isinstance'.  But then I would sort of expect '3 in [1,2,3,4]' to behave like
'isinstance(3, [1,2,3,4])'

Or you could just say that type objects implement a __contains__ method that
does an isinstance.  But if classes and types are unified, that would get in
the way of classes that define __contains__.  You'd have to think of it as a
class method (or a metaclass method), which is in a different namespace than
instance methods.  Or something.

It's a nice syntax, but it seems a bit confusing to me.



More information about the Python-list mailing list