<div dir="ltr"><div>This is one of the unfortunate effects of the existence of "old-style" classes in Python 2. The old-style class hierarchy is distinct from the new-style class hierarchy, but instances of old-style classes are still objects (since in Python, *everything* is an object).<br><br></div>For new code, and whenever you have an opportunity to refactor old code, you should use new-style classes, by inheriting your class from object (or from another class that inherits from object).<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 21, 2014 at 9:43 AM, Andreas Maier <span dir="ltr"><<a href="mailto:MAIERA@de.ibm.com" target="_blank">MAIERA@de.ibm.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Hi. Today, I ran across this, in Python 2.7.6:<br>
<br>
>>> class C:<br>
... pass<br>
...<br>
>>> issubclass(C,object)<br>
False<br>
>>> isinstance(C(),object)<br>
True <-- ???<br>
<br>
The description of isinstance() in Python 2.7 does not reveal this result<br>
(to my reading).<br>
<br>
>From a duck-typing perspective, one would also not guess that an instance<br>
of C would be considered an instance of object:<br>
<br>
>>> dir(C())<br>
['__doc__', '__module__']<br>
>>> dir(object())<br>
['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__',<br>
'__hash__', '__init__', '__new__', '__reduce__<br>
', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__',<br>
'__subclasshook__']<br>
<br>
-> What is the motivation for isinstance(C,object) to return True in Python<br>
2.7?<br>
<br>
Andy<br>
<br>
Andreas Maier<br>
IBM Senior Technical Staff Member, Systems Management Architecture & Design<br>
IBM Research & Development Laboratory Boeblingen, Germany<br>
<a href="mailto:maiera@de.ibm.com">maiera@de.ibm.com</a>, <a href="tel:%2B49-7031-16-3654" value="+497031163654">+49-7031-16-3654</a><br>
________________________________________________________________________<br>
IBM Deutschland Research & Development GmbH<br>
Vorsitzende des Aufsichtsrats: Martina Koederitz<br>
Geschaeftsfuehrung: Dirk Wittkopp<br>
Sitz der Gesellschaft: Boeblingen<br>
Registergericht: Amtsgericht Stuttgart, HRB 243294<br>
<br>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" target="_blank">https://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" target="_blank">https://mail.python.org/mailman/options/python-dev/guido%40python.org</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)
</div>