| Store | Cart

[Python-Dev] isinstance() on old-style classes in Py 2.7

From: Andreas Maier <MAI...@de.ibm.com>
Tue, 21 Oct 2014 18:43:09 +0200
Hi. Today, I ran across this, in Python 2.7.6:

>>> class C:
...   pass
...
>>> issubclass(C,object)
False
>>> isinstance(C(),object)
True   <-- ???

The description of isinstance() in Python 2.7 does not reveal this result
(to my reading).

From a duck-typing perspective, one would also not guess that an instance
of C would be considered an instance of object:

>>> dir(C())
['__doc__', '__module__']
>>> dir(object())
['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__',
'__hash__', '__init__', '__new__', '__reduce__
', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__',
'__subclasshook__']

-> What is the motivation for isinstance(C,object) to return True in Python
2.7?

Andy

Andreas Maier
IBM Senior Technical Staff Member, Systems Management Architecture & Design
IBM Research & Development Laboratory Boeblingen, Germany
mai...@de.ibm.com, +49-7031-16-3654
________________________________________________________________________
IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294

_______________________________________________
Python-Dev mailing list
Pyth...@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/python-dev-ml%40activestate.com

Recent Messages in this Thread
Andreas Maier Oct 21, 2014 04:43 pm
Guido van Rossum Oct 21, 2014 05:13 pm
Barry Warsaw Oct 21, 2014 05:53 pm
Guido van Rossum Oct 21, 2014 06:22 pm
Barry Warsaw Oct 21, 2014 06:28 pm
Mark Shannon Oct 21, 2014 05:25 pm
Messages in this thread