[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
True
>>> type(MyInt(5)) is int      # int superclass not included
False
>>> type(MyInt(5)) is MyInt    # check for specific type
True

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

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13387>
_______________________________________


More information about the Python-bugs-list mailing list