This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: `isinstance` function does not handle types that are their own type
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.4
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: abarry, ppperry
Priority: normal Keywords:

Created on 2016-05-29 22:52 by ppperry, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg266644 - (view) Author: (ppperry) Date: 2016-05-29 22:52
If one executes the following statements:

>>> class metatype(type):pass
>>> class x(type,metaclass=metatype):pass
>>> x.__class__ = x

, one gets a type that is it's own type: (`type(x) is x`). However, `isinstance(x,x)` unexpectedly returns False. How is my `x` type not an instance of itself.
msg266646 - (view) Author: Anilyka Barry (abarry) * (Python triager) Date: 2016-05-29 22:56
Works for me:

>>> class meta(type): pass
...
>>> class X(type, metaclass=meta): pass
...
>>> X.__class__ = X
>>> type(X) is X
True
>>> isinstance(X, X)
True
msg266647 - (view) Author: Anilyka Barry (abarry) * (Python triager) Date: 2016-05-29 23:04
This seems as though you might be using an older version of the interpreter (I tested in 3.4.3, 3.5.1 and 3.6.0a1+). Where did you get your interpreter? The official releases are on https://www.python.org/downloads/ - if you got it somewhere else, that might be something for whoever packaged your installer to fix.
msg266648 - (view) Author: (ppperry) Date: 2016-05-29 23:14
Never mind this issue, I was confused when reporting.
History
Date User Action Args
2022-04-11 14:58:31adminsetgithub: 71345
2016-05-29 23:14:16ppperrysetmessages: + msg266648
2016-05-29 23:04:16abarrysetmessages: + msg266647
2016-05-29 22:56:03abarrysetstatus: open -> closed

nosy: + abarry
messages: + msg266646

resolution: works for me
stage: resolved
2016-05-29 22:53:11ppperrysettitle: `isnstance` function does not handle types that are their own type -> `isinstance` function does not handle types that are their own type
2016-05-29 22:53:01ppperrysettitle: `isnstance` builtin does not handle types that are their own type -> `isnstance` function does not handle types that are their own type
2016-05-29 22:52:49ppperrysettype: behavior
2016-05-29 22:52:41ppperrycreate