Alex Rivera | Logout

Python Default Inheritance?

Asked 2011-02-05T09:04:07.807
11

If I define a class in Python such as:

class AClass:
   __slots__ = ['a', 'b', 'c']

Which class does it inherit from? It doesn't seem to inherit from object.

Edit
Report

1 Answer

15

If you define a class and don't declare any specific parent, the class becomes a "classic class", which behaves a bit differently than "new-style classes" inherited from object. See here for more details: http://docs.python.org/release/2.5.2/ref/node33.html

Classic classes don't have a common root, so essentially, your AClass doesn't inherit from any class.

Note that this is specific to Python versions before 3.0. In Python 3, all classes are new-style classes and inherit implicitly from object, if no other parent is declared.

answered 2011-02-05T09:08:43.270

Your Answer