python / typeshed

Collection of library stubs for Python, with static types
Other
4.39k stars 1.77k forks source link

Support for Python 3.13.0 generator.close() return value (Python issue #104770) #13128

Closed CodeMouse92 closed 10 hours ago

CodeMouse92 commented 11 hours ago

Bug Report

As of Python 3.13, it is possible to return a value from a simple coroutine (generator): https://github.com/python/cpython/issues/104770

This is supported by the type hints. However, Mypy does not consider the generator/coroutine annotation to determine the return type of close().

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.13&gist=c1ef127cdbc6359a99c346b0ee15c8b5

Expected Behavior

If the simple coroutine (generator) f is annotated to return a type (e.g. int), then the call to f.close() should be recognized as returning an int.

Actual Behavior

error: "close" of "Generator" does not return a value (it only ever returns None)  [func-returns-value]

Your Environment

brianschubert commented 11 hours ago

Thanks! This looks like an issue with Generator's stubs in typeshed. I opened https://github.com/python/typeshed/pull/13127