Determining if an object is a class?

Clay Culver Clay_Culver at yahoo.com
Thu Jul 13 14:16:37 EDT 2006


Dino Viehland wrote:
> The first check is also off - it should if issubclass(type(Test), type): otherwise you miss the metaclass case:
>
> class foo(type): pass
>
> class Test(object):
>     __metaclass__ = foo
>
> obj = Test
> if type(obj) == type: 'class obj'
> else: 'not a class'
>
> just on the off-chance you run into a metaclass :)

Ah right...it's so easy to forget about metaclassing, despite how easy
Python makes it.  Good catch, thanks.




More information about the Python-list mailing list