Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy the coroutine status in deprecated #438

Merged
merged 8 commits into from
Aug 29, 2024

Conversation

srittau
Copy link
Collaborator

@srittau srittau commented Jul 23, 2024

No description provided.

@AlexWaygood
Copy link
Member

AlexWaygood commented Jul 23, 2024

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
Copy link
Collaborator Author

srittau commented Jul 23, 2024

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
Copy link
Member

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):

skip_if_py313_beta_1 = skipIf(
sys.version_info[:5] == (3, 13, 0, 'beta', 1),
"Bugfixes will be released in 3.13.0b2"
)

Something like this:

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

src/test_typing_extensions.py Outdated Show resolved Hide resolved
Comment on lines +2911 to +2914
if sys.version_info >= (3, 12):
wrapper = inspect.markcoroutinefunction(wrapper)
else:
wrapper._is_coroutine = asyncio.coroutines._is_coroutine
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the _is_coroutine thing also exists on the CPython main branch. I think it would be nice for @deprecated to work consistently across Python versions as much as possible, so maybe we could just add the _is_coroutine marker unconditionally, even though it isn't really necessary on py312+:

Suggested change
if sys.version_info >= (3, 12):
wrapper = inspect.markcoroutinefunction(wrapper)
else:
wrapper._is_coroutine = asyncio.coroutines._is_coroutine
wrapper._is_coroutine = asyncio.coroutines._is_coroutine
if sys.version_info >= (3, 12):
wrapper = inspect.markcoroutinefunction(wrapper)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be wary about this. Why access a private item when not necessary? Especially since it gets overwritten immediately after?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, we can leave this.

Copy link
Member

@AlexWaygood AlexWaygood Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, well, it would fix the asyncio.coroutines.iscoroutinefunction() test that's currently failing on Python 3.13.0b4. But I suppose that test could easily just be skipped only if we're on Python >=3.13 and <3.13.0rc1

src/test_typing_extensions.py Outdated Show resolved Hide resolved
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@srittau srittau closed this Aug 29, 2024
@srittau srittau reopened this Aug 29, 2024
@srittau
Copy link
Collaborator Author

srittau commented Aug 29, 2024

CI is passing now.

@JelleZijlstra JelleZijlstra merged commit d9509f9 into python:main Aug 29, 2024
40 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants