Why does Python use the None type hint instead of NoneType?

Viewed 303

For Python's None object, the type hint None is used instead of its actual type, NoneType. From the docs:

Note that None as a type hint is a special case and is replaced by type(None).

I find this confusing and no further explanation is given.

Does anyone know the reason behind this?

1 Answers

It's just a design choice. There's no particular reason behind it.

Writing def fn(x: None) -> None is more concise than def fn(x: NoneType) -> NoneType (and IMHO also clearer).

It's also consistent with other type hints: List, Dict, etc, which are all a single word (the same as the associated built-in function) with an uppercase first letter.

Related