Issue 27158: isinstance function does not handle types that are their own type (original) (raw)

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:31 admin set github: 71345
2016-05-29 23:14:16 ppperry set messages: +
2016-05-29 23:04:16 abarry set messages: +
2016-05-29 22:56:03 abarry set status: open -> closednosy: + abarrymessages: + resolution: works for mestage: resolved
2016-05-29 22:53:11 ppperry set title: `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:01 ppperry set title: `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:49 ppperry set type: behavior
2016-05-29 22:52:41 ppperry create