python / typing_extensions

Backported and experimental type hints for Python
Other
446 stars 110 forks source link

Copy the coroutine status in deprecated #438

Closed srittau closed 2 months ago

AlexWaygood commented 4 months ago

On earlier versions of Python, there were two different functions, inspect.iscoroutinefunction and asyncio.coroutines.iscoroutinefunction. This was confusing, because they did two different things: inspect.iscoroutinefunction was strict about only returning True for functions that actually had the CO_COROUTINE code-flag set, whereas asyncio.coroutines.iscoroutinefunction also considered functions decorated with @types.coroutine to be coroutines, even though these functions did not have that code-flag set.

There's not much we can do for inspect.iscoroutinefunction on the earlier versions of Python (because, before the two iscoroutinefunction functions were merged, it was stricter than it is now), but we can hack asyncio.coroutines.iscoroutinefunction by doing decorated_function._is_coroutine = asyncio.coroutines._is_coroutine: https://github.com/python/cpython/blob/d542a9be51776e8d589363ee15164dec8dbd3a76/Lib/asyncio/coroutines.py#L17-L24

srittau commented 4 months ago

The 3.13 test fails, because this hasn't been implemented in 3.13 yet. It should be fixed with 3.13.rc1. What's the best course of action?

AlexWaygood commented 4 months ago

The 3.13 test fails, because this hasn't been implemented in 3.13 yet. It should be fixed with 3.13.rc1. What's the best course of action?

I'd add a decorator like the one we already have here (which we can probably delete at this point):

https://github.com/python/typing_extensions/blob/70cec91bec65155dc339d631ede2a933582558df/src/test_typing_extensions.py#L125-L128

Something like this:

 skip_if_py313_beta = skipIf( 
     sys.version_info[:4] == (3, 13, 0, 'beta'), 
     "Bugfixes will be released in 3.13.0rc1"
 )
srittau commented 2 months ago

CI is passing now.