2.2 features
Skip Montanaro
skip at pobox.com
Tue Jul 31 15:28:05 EDT 2001
>> I guess I'm confused, but if isinstance(x, type) is true isn't
>> issubclass(x.__class__, type) also true?
Guido> You are indeed confused. :)
Guido> Seems you confuse isinstance(x, y) with issubclass(x, y). These
Guido> are very different. x in y can map to at most one of these (for
Guido> y a type object).
Here's an example that makes concrete what I was thinking:
>>> class Foo:
... pass
...
>>> class Bar(Foo):
... pass
...
>>> x = Bar()
>>> isinstance(x, Foo)
1
>>> issubclass(Bar, Foo)
1
>>> issubclass(x.__class__, Foo)
1
Why can't the "in" operator grok all three of these possibilities?
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)
I assume x can't be both an instance and a class at the same time.
Skip
More information about the Python-list
mailing list