Since Python 3 made explicitly inheriting from
object unnecessary, these two lines are equivalent
X = type('X', (object,), dict(a=1))` X = type('X', (), dict(a=1))`
It’s surprising that you have to pass an empty tuple to
type(). It wasn’t obvious what
(object,), was before and now on Python 3 it’s less obvious.
One way to solve this would be a 3rd signature for
X = type('X', dict(a=1))
This is pretty ugly because it makes the 3 argument form surprising, since the third
bases argument comes from the middle:
class type(object) class type(name, dict) class type(name, bases, dict)
instead of the more sensible
class type(object) class type(name, dict[, bases])
but you can’t break backwards compatibility with all the code that uses the
class type(name, bases, dict) form.