Is there any reason to do to multiple inheritance with object?

56 Views Asked by At

While reviewing some code, it has a structure like

class Bar(Foo, object):

Which seems like it could easily be written instead as

class Bar(Foo):

The functionally appears at least the same the simple chain of inheritance for the purpose of determining method resolution, and both Foo and Bar are isinstance() of object in both cases

B → F → o

B → F
  ↳ o

Is there any practical benefit to a multiple inheritance from object?

1

There are 1 best solutions below

1
juanpa.arrivillaga On BEST ANSWER

Almost certainly, no, it shouldn't have any effect, the MRO is still the same:

>>> class Foo: pass
...
>>> class Bar(Foo, object): pass
...
>>> Bar.mro()
[<class '__main__.Bar'>, <class '__main__.Foo'>, <class 'object'>]

So:

>>> class Bar(Foo): pass
...
>>> Bar.mro()
[<class '__main__.Bar'>, <class '__main__.Foo'>, <class 'object'>]

Potentially, I suppose, it could have an effect if any code introspects __bases__:

>>> class Bar(Foo): pass
...
>>> Bar.__bases__
(<class '__main__.Foo'>,)
>>> class Bar(Foo, object): pass
...
>>> Bar.__bases__
(<class '__main__.Foo'>, <class 'object'>)

But I highly suspect this is just a typo