-
-
Notifications
You must be signed in to change notification settings - Fork 133
Description
If a function returns None, it should be explicitly annotated as-such for code to be fully-typed. According to PEP-484 if no return type is provided, Any should be assumed. Some type checkers allow enabling leniency for this, but in strict mode do not allow it.
Relevant extracts from PEP 484 "the meaning of annotations":
For a checked function, the default annotation for arguments and for the return type is
Any.
Note that the return type of
__init__ought to be annotated with-> None. The reason for this is subtle. If__init__assumed a return annotation of-> None, would that mean that an argument-less, un-annotated__init__method should still be type-checked? Rather than leaving this ambiguous or introducing an exception to the exception, we simply say that__init__ought to have a return annotation; the default behavior is thus the same as for other methods.