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
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
- Add `typing_extensions.get_annotations`, a backport of
`inspect.get_annotations` that adds features specified
by PEP 649. Patches by Jelle Zijlstra and Alex Waygood.
- Copy the coroutine status of functions and methods wrapped
with `@typing_extensions.deprecated` when using Python 3.12
or above. Patch by Sebastian Rittau.

# Release 4.12.2 (June 7, 2024)

Expand Down
30 changes: 30 additions & 0 deletions src/test_typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
# 3.13 drops support for the keyword argument syntax of TypedDict
TYPING_3_13_0 = sys.version_info[:3] >= (3, 13, 0)

# 3.13.0rc1 changes @deprecated behavior
TYPING_3_13_BETA = sys.version_info[:4] == (3, 13, 0, 'beta')

# https://github.com/python/cpython/pull/27017 was backported into some 3.9 and 3.10
# versions, but not all
HAS_FORWARD_MODULE = "module" in inspect.signature(typing._type_check).parameters
Expand Down Expand Up @@ -850,6 +853,33 @@ def d(): pass
isinstance(cell.cell_contents, deprecated) for cell in d.__closure__
))

def test_inspect(self):
@deprecated("depr")
def sync():
pass

@deprecated("depr")
async def coro():
pass

class Cls:
@deprecated("depr")
def sync(self):
pass

@deprecated("depr")
async def coro(self):
pass

self.assertFalse(inspect.iscoroutinefunction(sync))
self.assertFalse(inspect.iscoroutinefunction(Cls.sync))
if sys.version_info >= (3, 12) and not TYPING_3_13_BETA:
self.assertTrue(inspect.iscoroutinefunction(coro))
self.assertTrue(inspect.iscoroutinefunction(Cls.coro))
else:
self.assertFalse(inspect.iscoroutinefunction(coro))
self.assertFalse(inspect.iscoroutinefunction(Cls.coro))
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved


class AnyTests(BaseTestCase):
def test_can_subclass(self):
Expand Down
4 changes: 4 additions & 0 deletions src/typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2899,12 +2899,16 @@ def __init_subclass__(*args, **kwargs):
return arg
elif callable(arg):
import functools
import inspect

@functools.wraps(arg)
def wrapper(*args, **kwargs):
warnings.warn(msg, category=category, stacklevel=stacklevel + 1)
return arg(*args, **kwargs)

if sys.version_info >= (3, 12) and inspect.iscoroutinefunction(arg):
wrapper = inspect.markcoroutinefunction(wrapper)

arg.__deprecated__ = wrapper.__deprecated__ = msg
return wrapper
else:
Expand Down
Loading