In python 3.x, it is common to use return type annotation of a function, such as:
def foo() -> str:
return "bar"
What is the correct annotation for the "void" type?
I'm considering 3 options:
def foo() -> None:
None
is not a type,def foo() -> type(None):
NoneType
,def foo():
Option 2. seems the most logical to me, but I've already seen some instances of 1.
Use option 1 for simplicity & adherence to spec.
def foo() -> None
Option 1 & 2 are the 'same' as per PEP 484 -- Type Hints, ...
When used in a type hint, the expression
None
is considered equivalent totype(None)
.
but the type-hinting specification does not use type(...)
.
This is why most of the examples use None
as return type.