2.2 features

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Tue Jul 31 22:34:54 CEST 2001


Tue, 31 Jul 2001 14:28:05 -0500, Skip Montanaro <skip at pobox.com> pisze:

>     x in Foo                         same as isinstance(x, Foo)
>     Bar in Foo                       same as issubclass(Bar, Foo)
>     x.__class__ in Foo               same as issubclass(x.__class__, Foo)

It makes impossible to check whether an object is an instance of Foo
using the 'in' operator. For example Bar is not an instance of Foo
but 'Bar in Foo' would be true.

It also makes impossible to check whether an object is a sublass of Foo.
For example x is not a subclass of Foo but 'x in Foo' would be true.

In effect it doesn't correctly answer either question.

> I assume x can't be both an instance and a class at the same time.

Even if it was true, it would require the programmer to check this
condition, instead of letting 'in' check it.

It's not true in a broader view where types and classes are treated
similarly. For example 'type in type' is true in both senses and 'int
in string' is false in both senses, but you can't distinguish between
classes and instances here - all objects involved are type objects.

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list