Joesph <someone...@gmail.com> added the comment:

Beautiful, thank you. This should be in the isinstance documentation for
clarity.
On May 29, 2011 9:28 PM, "R. David Murray" <rep...@bugs.python.org> wrote:
>
> R. David Murray <rdmur...@bitdance.com> added the comment:
>
> You are correct, B is not an instance of A. But both B and A are instances
of 'type':
>
>>>> class A:
> ... pass
> ...
>>>> class B(A):
> ... pass
> ...
>>>> isinstance(A, type)
> True
>>>> isinstance(B, type)
> True
>>>>
>
> And type is a subclass of object. isinstance is correct, because Python is
consistent. As we said, *everything* is an object.
>
> If you want to know if something is a class, you can check isinstance(X,
type):
>
>>>> a = A()
>>>> isinstance(a, type)
> False
>
> ----------
>
> _______________________________________
> Python tracker <rep...@bugs.python.org>
> <http://bugs.python.org/issue12203>
> _______________________________________

----------
Added file: http://bugs.python.org/file22186/unnamed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue12203>
_______________________________________
<p>Beautiful, thank you. This should be in the isinstance documentation for 
clarity.</p>
<div class="gmail_quote">On May 29, 2011 9:28 PM, &quot;R. David Murray&quot; 
&lt;<a href="mailto:rep...@bugs.python.org";>rep...@bugs.python.org</a>&gt; 
wrote:<br type="attribution">&gt; <br>&gt; R. David Murray &lt;<a 
href="mailto:rdmur...@bitdance.com";>rdmur...@bitdance.com</a>&gt; added the 
comment:<br>
&gt; <br>&gt; You are correct, B is not an instance of A.  But both B and A are 
instances of &#39;type&#39;:<br>&gt; <br>&gt;&gt;&gt;&gt; class A:<br>&gt; ...  
 pass<br>&gt; ...<br>&gt;&gt;&gt;&gt; class B(A):<br>&gt; ...    pass<br>
&gt; ...<br>&gt;&gt;&gt;&gt; isinstance(A, type)<br>&gt; 
True<br>&gt;&gt;&gt;&gt; isinstance(B, type)<br>&gt; True<br>&gt;&gt;&gt;&gt; 
<br>&gt; <br>&gt; And type is a subclass of object.  isinstance is correct, 
because Python is consistent.  As we said, *everything* is an object.<br>
&gt; <br>&gt; If you want to know if something is a class, you can check 
isinstance(X, type):<br>&gt; <br>&gt;&gt;&gt;&gt; a = A()<br>&gt;&gt;&gt;&gt; 
isinstance(a, type)<br>&gt; False<br>&gt; <br>&gt; ----------<br>&gt; <br>
&gt; _______________________________________<br>&gt; Python tracker &lt;<a 
href="mailto:rep...@bugs.python.org";>rep...@bugs.python.org</a>&gt;<br>&gt; 
&lt;<a 
href="http://bugs.python.org/issue12203";>http://bugs.python.org/issue12203</a>&gt;<br>
&gt; _______________________________________<br></div>
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to