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, "R. David Murray"
<<a href="mailto:rep...@bugs.python.org">rep...@bugs.python.org</a>>
wrote:<br type="attribution">> <br>> R. David Murray <<a
href="mailto:rdmur...@bitdance.com">rdmur...@bitdance.com</a>> added the
comment:<br>
> <br>> You are correct, B is not an instance of A. But both B and A are
instances of 'type':<br>> <br>>>>> class A:<br>> ...
pass<br>> ...<br>>>>> class B(A):<br>> ... pass<br>
> ...<br>>>>> isinstance(A, type)<br>>
True<br>>>>> isinstance(B, type)<br>> True<br>>>>>
<br>> <br>> And type is a subclass of object. isinstance is correct,
because Python is consistent. As we said, *everything* is an object.<br>
> <br>> If you want to know if something is a class, you can check
isinstance(X, type):<br>> <br>>>>> a = A()<br>>>>>
isinstance(a, type)<br>> False<br>> <br>> ----------<br>> <br>
> _______________________________________<br>> Python tracker <<a
href="mailto:rep...@bugs.python.org">rep...@bugs.python.org</a>><br>>
<<a
href="http://bugs.python.org/issue12203">http://bugs.python.org/issue12203</a>><br>
> _______________________________________<br></div>
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com