Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 796035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:34:39+00:00 2026-05-14T22:34:39+00:00

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

  • 0

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.

Clarification: I’m looking to understand WHY __subclasses__() isn’t available in old-style, i get that the method doesn’t exist for old-style classes but I don’t get what it is about new-style that makes these new functions possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:34:39+00:00Added an answer on May 14, 2026 at 10:34 pm
    class Foo(object):
        pass
    

    The class above is a “new-style” class because it inherits from the object class. New-style classes provide a lot of extra framework that “old-style” classes do not have. One particular attribute of a new-style class is to be able to determine the subclasses of the class with the __subclasses__ method.

    There is some good discussion about new-style classes and the __subclasses__ method which use to be completely undocumented. ( Here is an unofficial explanation from Tim Peters, though. )

    “Each new-style class keeps a list of weak references to its immediate subclasses. This method returns a list of all those references still alive.”

    So to answer your question, the __subclasses__ functionality is not available because in your second example:

    class Foo():
        pass
    

    The old-style class Foo does not inherit from object (so it’s not a new-style class) and there for does not inherit the __subclasses__ method.

    Note, if you don’t understand why an old-style class does not have the __subclasses__ method you could always fire up a python interpreter and do some inspection with dir

    >>> class Foo(object):
    ...     pass
    ...
    >>> dir(Foo.__class__)
    ['__abstractmethods__', '__base__', '__bases__', '__basicsize__', '__call__', '__class__', '__delattr__', '__dict__', '__dictoffset__', '__doc__', '__
    eq__', '__flags__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__instancecheck__', '__itemsize__', '__le__', '__lt
    __', '__module__', '__mro__', '__name__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__s
    ubclasscheck__', '__subclasses__', '__subclasshook__', '__weakrefoffset__', 'mro']
    >>> class Bar():
    ...     pass
    ...
    >>> dir(Bar.__class__)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: class Bar has no attribute '__class__'
    >>> dir(Bar)
    ['__doc__', '__module__']
    >>> dir(Foo)
    ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '
    __reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can somebody explain to me why the following works: template<class T> class MyTemplateClass {
Can somebody please explain how this works in jQuery. I tried to find some
I need to clear a basic concept. This code works fine. Can somebody explain
Can somebody explain me why this Map<String, List<String>> foo = new HashMap<String, LinkedList<String>>(); generates
Can somebody explain to me what this does in javascript? (function (x,y){}(x,y)); or this
Can somebody explain me the flow of control in this tutorial : http://www.vogella.de/articles/AndroidSQLite/article.html#tutorialusecp I
Can somebody please explain to me the meaning of this line of code? val
Can somebody explain to me where I'm going wrong with this login setup? I've
Can sombody explain how this works? int x, y; .... (some_condition ? x :
Can somebody please explain this to me: I have a label and I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.