I need some help how to write the type hints, and it is not purely technical.
As an example, imagine a get_state() function returning the current state as a string.
The documentation states the initialize() must be called first and the result of get_state() is undefined prior to initialization. Actually it returns None when uninitialized, but that is an implementation detail.
The annotation could be:
get_state() -> strwhich is correct assuming a proper usage. I find it helpful from the developer's point of view, butmypycomplains because it is clear that the return value could be alsoNone.get_state() -> str|Nonewhich matches the reality the most, but may change in the future and it introducesmypywarnings everywhere the return value is used and is obviously expected to be a string there.get_state() -> Anywhich exactly matches the documented API, but is useless.
So, who is the main recipient of the information in the annotation? Is it the developer getting additional information when reading the code? Or is it the type checker tool like the mypy that tries to find possible problems?