[Python-ideas] add __contains__ into the "type" object

Steven D'Aprano steve at pearwood.info
Tue Feb 28 18:12:50 EST 2017


On Wed, Mar 01, 2017 at 07:02:23AM +0800, 语言破碎处 wrote:
> 
> where we use types?
>     almost:
>         isinstance(obj, T);
>         # issubclass(S, T);
> 
> Note that TYPE is SET;

What does that mean? I don't understand.


>     if we add __contains__ and __le__ into "type",
>     then things become:
>         obj in T;

But obj is **not** in T, since T is a type, not a container.

"is-a" tests are not the same as "in" tests. They are completely 
unrelated comparisons.

http://www.w3resource.com/java-tutorial/inheritance-composition-relationship.php

The Wikipedia page on is-a is terribly complicated, but folks may get 
something from it:

https://en.wikipedia.org/wiki/Is-a



-- 
Steve


More information about the Python-ideas mailing list