Python new-style classes and __subclasses__ function

Posted by Fraser Graham on Stack Overflow See other posts from Stack Overflow or by Fraser Graham
Published on 2010-05-20T19:28:30Z Indexed on 2010/05/20 19:30 UTC
Read the original article Hit count: 186

Filed under:

Can somebody explain to me why this works (in Python 2.5) :

class Foo(object):
    pass

class Bar(Foo):
    pass

print(Foo.__subclasses__())

but this doesn't :

class Foo():
    pass

class Bar(Foo):
    pass

print(Foo.__subclasses__())

The latter returns "AttributeError: class Foo has no attribute '__subclasses__'" but i'm not sure why. I know this is related to old-style vs. new-style classes but i'm not clear on why that would make this functionality unavailable.

© Stack Overflow or respective owner

Related posts about python