kms

Formatting Classes with Multiple Inheritance in

March 8, 2014

PEP 8 says that line length should generally be fewer than 80 characters. It doesn’t discuss formatting for classes with multiple inheritance, but we can infer a preferred style from the formatting for methods.

Consider this class with a long list of parent classes:

class OurClass(AMixin, AnotherMixin, SomeParentClass, AnotherParent, ThisIsJustTooMany):
    pass

This could be formatted:

class OurClass(
    AMixin,
    AnotherMixin,
    SomeParentClass,
    AnotherParent,
    ThisIsJustTooMany
):
    pass

Another formatting could be:

class OurClass(AMixin,
               AnotherMixin,
               SomeParentClass,
               AnotherParent,
               ThisIsJustTooMany):
    pass

Due to the way methods are formatted in PEP 8, a better style might be:

class OurClass(AMixin, AnotherMixin, SomeParentClass,
               AnotherParent, ThisIsJustTooMany):
    pass

I’m not sure here. I prefer the latter two. What would you prefer?