In Python 3.x, the correct annotation to indicate a function with no return value (similar to the "void" type in some other programming languages) is None. However, the second option you mentioned, def foo() -> type(None):, is the recommended way to annotate such functions.
Here's the preferred annotation for a function with no return value:
def foo() -> None:
# Function code
The None type represents the absence of a value in Python, and it serves as a special value to indicate no return value. While it's true that None is not a type in the strictest sense, it is commonly used in this context to indicate that the function does not return anything.
Using def foo(): without explicit return type information is also valid and will work as expected. However, explicitly indicating None as the return type provides additional clarity to both human readers and static type checkers. It makes it explicit that the function does not return any meaningful value.
Ultimately, the choice between options 1 and 2 is a matter of personal preference and style guidelines. Some developers may prefer to be explicit and use def foo() -> None, while others may choose to omit the return type annotation for simplicity. Both options are acceptable in Python.