from contextlib import contextmanager
@contextmanager
def foo() -> None:
yield
results in:
main.py:4: error: Argument 1 to "contextmanager" has incompatible type "Callable[[], None]"; expected "Callable[[], Iterator[Never]]" [arg-type]
main.py:5: error: The return type of a generator function should be "Generator" or one of its supertypes [misc]
A superficial take on a context manager (https://mypy-play.net/?mypy=latest&python=3.12&gist=68fae9f1b14467dc3a586f2473c9c419):
results in:
If I specify
Iterator[Never]
as suggested, it still doesn't work (https://mypy-play.net/?mypy=latest&python=3.12&gist=d644d5c880c5f04b0c54941a7cc8c4b2):results in:
Inspired by https://github.com/python/mypy/issues/3551 I switched it to
None
(https://mypy-play.net/?mypy=latest&python=3.12&gist=e825ee207b3fbcad373163f5618f467e):And now it works:
How? Wasn't
Never
(as in "never returns") supposed to not ask for a return value?