[docs] [issue13387] suggest assertIs(type(obj), cls) for exact type checking

Ezio Melotti report at bugs.python.org
Fri Nov 18 18:15:33 CET 2011

Ezio Melotti <ezio.melotti at gmail.com> added the comment:

> + To check for a specific type (without including superclasses) use
> + :func:`assertIs(type(obj), cls) <assertIs>`.
> Don’t you mean “without accepting subclasses”, not superclasses?

I mean:
>>> class MyInt(int): pass     # my specific type
>>> isinstance(MyInt(5), int)  # int superclass included
>>> type(MyInt(5)) is int      # int superclass not included
>>> type(MyInt(5)) is MyInt    # check for specific type

Do you think I should rephrase it (or maybe just remove the (...))?


Python tracker <report at bugs.python.org>

More information about the docs mailing list