Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue7390] inconsistent type return

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Nov 24, 2009, 4:37 AM

Post #1 of 4 (199 views)
Permalink
[issue7390] inconsistent type return

New submission from Sérgio Surkamp <sergio [at] gruposinternet>:

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).

----------
components: Interpreter Core
messages: 95670
nosy: surkamp
severity: normal
status: open
title: inconsistent type return
type: behavior
versions: Python 2.6

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7390>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 24, 2009, 4:43 AM

Post #2 of 4 (192 views)
Permalink
[issue7390] inconsistent type return [In reply to]

flox <laxyf [at] yahoo> added the comment:

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.

----------
nosy: +flox

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7390>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 24, 2009, 4:44 AM

Post #3 of 4 (194 views)
Permalink
[issue7390] inconsistent type return [In reply to]

Antoine Pitrou <pitrou [at] free> added the comment:

`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.

----------
nosy: +pitrou
resolution: -> invalid

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7390>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 24, 2009, 4:44 AM

Post #4 of 4 (195 views)
Permalink
[issue7390] inconsistent type return [In reply to]

Changes by Antoine Pitrou <pitrou [at] free>:


----------
status: open -> closed

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7390>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.