John Snow <js...@redhat.com> writes: > On 10/7/20 7:32 AM, Markus Armbruster wrote: >> Ignorant question: what's the difference between -> None (like here) and >> nothing (like __init__() above? > > This came up in Cleber's review, too. > > Mypy supports a gradual typing paradigm; it is designed to facilitate > what we are doing here: the gradual adding of types until we are able > to enforce static typing everywhere. > > To that end, mypy uses a simple heuristic to determine if a function > is "typed" or "untyped": did you use any type annotations for it? > > Meanwhile, __init__ never returns anything. You do not need to > annotate its return type. mypy knows what the return type is and must > be. In the case of __init__ with no parameters, it is both untyped and > strictly typed! > > Annotating the return type for no-parameter init methods convinces > mypy that this is a strictly typed method. It doesn't do this > automatically, because doing so might enable more checks than you were > ready for simply because mypy was able to accurately surmise the > typing of just __init__. > > So it's just a little flip switch to enable strict typing, really. > > --js > > https://mypy.readthedocs.io/en/stable/class_basics.html#annotating-init-methods
I now understand we can omit -> None, except when it's the only type hint, because omitting it then would make it untyped, which is not what we want. Is this just for __init__(), or is it for any function that doesn't return anything?