For a class definition with no inheritance, is there any difference or stylistic preference between:
class M:
pass
and
class M():
pass
?
I couldn't find it mentioned in PEP8.
For a class definition with no inheritance, is there any difference or stylistic preference between:
class M:
pass
and
class M():
pass
?
I couldn't find it mentioned in PEP8.
It's not in PEP 8 because in the early days of Python 3, Guido suggested that everyone should be explicitly inheriting from object
during the transition period. Possibly this should be updated…
However, if you look at all of the examples in the documentation that don't use class M(object):
, they all use the first format, class M:
.
For example, see Class Definition Syntax, Class Objects, and all of the following sections in the tutorial. (And note that the tutorial doesn't even explain that you can use zero base classes inside the parentheses.)
(Plus, at least to me, the second format implies that you're explicitly trying to inherit from nothing, which is misleading, while the first implies that you're just doing whatever the default is.)