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: inconsistent type return
Type: behavior Stage:
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: flox, pitrou, surkamp
Priority: normal Keywords:

Created on 2009-11-24 12:37 by surkamp, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg95670 - (view) Author: Sérgio Surkamp (surkamp) Date: 2009-11-24 12:37
The type function returns inconsistent value depending on class hierarchy.

>>> class X:
...     pass
... 
>>> x = X()
>>> type(x)
<type 'instance'>
>>> class Y(object):
...     pass
... 
>>> x = Y()
>>> type(x)
<class '__main__.Y'>
>>> 
>>> class Z(X):
...     pass
...  
>>> x = Z()
>>> type(x)
<type 'instance'>
>>> class K(Y):
...     pass
...   
>>> x = K()
>>> type(x)
<class '__main__.K'>

All should reply 'instance'. As long as I have read on documentation the
only way to change the type function return is by writing a
__metaclass__ (PEP3115).
msg95671 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2009-11-24 12:43
The relevant documentation for Python 2.6 is there.
http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes

The PEP 3115 is implemented for Python >= 3.0.

There's nothing wrong.
msg95672 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-11-24 12:44
`instance` means it is an instance of an old-style class. Old-style
classes are classes which don't have `object` in their inheritance
hierarchy.
On the other hand, for instance new-style classes type() returns the
actual class.
Bottom line: this is by design. Of course in an ideal world (or in
Python 3) there are only new-style classes, but we had to maintain
compatibility, and that's why there are two slightly different object
models cohabiting in Python 2.x.
History
Date User Action Args
2022-04-11 14:56:55adminsetgithub: 51639
2009-11-24 12:44:22pitrousetstatus: open -> closed
2009-11-24 12:44:16pitrousetresolution: not a bug

messages: + msg95672
nosy: + pitrou
2009-11-24 12:43:48floxsetnosy: + flox
messages: + msg95671
2009-11-24 12:37:26surkampcreate