# Two argument form of \`type()\`

**URL:** <https://discuss.python.org/t/two-argument-form-of-type/5745>\
**Category:** Ideas\
**Created:** [November 14, 2020, 4:53am UTC](https://discuss.python.org/t/two-argument-form-of-type/5745 "2020-11-14T04:53:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aoeu](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@aoeu](https://discuss.python.org/u/aoeu)\
**Post date:** [November 14, 2020, 4:53am UTC](https://discuss.python.org/t/two-argument-form-of-type/5745/1 "2020-11-14T04:53:45Z")

</div>

Since Python 3 made explicitly inheriting from `object` unnecessary, these two lines are equivalent

```python
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 `type()`:

```python
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:

```auto
class type(object)
class type(name, dict)
class type(name, bases, dict)

```

instead of the more sensible

```auto
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.

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [November 14, 2020, 9:50am UTC](https://discuss.python.org/t/two-argument-form-of-type/5745/2 "2020-11-14T09:50:52Z")

</div>

I disagree with your statements:

“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.”

Firstly, you don’t have to pass an empty tuple.

And secondly, of course it is obvious what `(object,)` is, if you know  
what `type` does. It’s a tuple of superclasses.

The `type` class requires a tuple of superclasses (notice plural)  
equivalent to what you would enter in a class statement:

```
class MyClass(Spam, Eggs, Cheese, Aardvark):
    pass

# Equivalent to:
MyClass = type("MyClass", (Spam, Eggs, Cheese, Aardvark), {})

```

Clearly it doesn’t have to be an empty tuple. And clearly you can leave  
out `object` if you wish.

It would be surprising if you _didn’t_ pass a tuple. How else can we  
handle a positional argument in the middle of the parameter list? The  
signature of `range` is very unusual, and we should have a really good  
reason for emulating that in other functions.

So if you have no explicit bases, the natural way to pass that is with  
an empty tuple. An empty tuple implies `(object,)`, just as leaving out  
the superclasses in the class statement does. So what’s the problem here  
you are trying to solve?

`type` already has a complex signature. Let’s not make it even more  
complex, and rather confusing, without a strong reason.
