|
1 | 1 | import abc
|
| 2 | +import asyncio |
2 | 3 | import collections
|
3 | 4 | import collections.abc
|
4 | 5 | import contextlib
|
|
115 | 116 | # and adds PEP 695 to CPython's grammar
|
116 | 117 | TYPING_3_12_0 = sys.version_info[:3] >= (3, 12, 0)
|
117 | 118 |
|
| 119 | +# @deprecated works differently in Python 3.12 |
| 120 | +TYPING_3_12_ONLY = (3, 12) <= sys.version_info < (3, 13) |
| 121 | + |
118 | 122 | # 3.13 drops support for the keyword argument syntax of TypedDict
|
119 | 123 | TYPING_3_13_0 = sys.version_info[:3] >= (3, 13, 0)
|
120 | 124 |
|
| 125 | +# 3.13.0.rc1 fixes a problem with @deprecated |
| 126 | +TYPING_3_13_0_RC = sys.version_info[:4] >= (3, 13, 0, "candidate") |
| 127 | + |
121 | 128 | # https://github.com/python/cpython/pull/27017 was backported into some 3.9 and 3.10
|
122 | 129 | # versions, but not all
|
123 | 130 | HAS_FORWARD_MODULE = "module" in inspect.signature(typing._type_check).parameters
|
@@ -850,6 +857,37 @@ def d(): pass
|
850 | 857 | isinstance(cell.cell_contents, deprecated) for cell in d.__closure__
|
851 | 858 | ))
|
852 | 859 |
|
| 860 | +@deprecated("depr") |
| 861 | +def func(): |
| 862 | + pass |
| 863 | + |
| 864 | +@deprecated("depr") |
| 865 | +async def coro(): |
| 866 | + pass |
| 867 | + |
| 868 | +class Cls: |
| 869 | + @deprecated("depr") |
| 870 | + def func(self): |
| 871 | + pass |
| 872 | + |
| 873 | + @deprecated("depr") |
| 874 | + async def coro(self): |
| 875 | + pass |
| 876 | + |
| 877 | +class DeprecatedCoroTests(BaseTestCase): |
| 878 | + def test_asyncio_iscoroutinefunction(self): |
| 879 | + self.assertFalse(asyncio.coroutines.iscoroutinefunction(func)) |
| 880 | + self.assertFalse(asyncio.coroutines.iscoroutinefunction(Cls.func)) |
| 881 | + self.assertTrue(asyncio.coroutines.iscoroutinefunction(coro)) |
| 882 | + self.assertTrue(asyncio.coroutines.iscoroutinefunction(Cls.coro)) |
| 883 | + |
| 884 | + @skipUnless(TYPING_3_12_ONLY or TYPING_3_13_0_RC, "inspect.iscoroutinefunction works differently on Python < 3.12") |
| 885 | + def test_inspect_iscoroutinefunction(self): |
| 886 | + self.assertFalse(inspect.iscoroutinefunction(func)) |
| 887 | + self.assertFalse(inspect.iscoroutinefunction(Cls.func)) |
| 888 | + self.assertTrue(inspect.iscoroutinefunction(coro)) |
| 889 | + self.assertTrue(inspect.iscoroutinefunction(Cls.coro)) |
| 890 | + |
853 | 891 |
|
854 | 892 | class AnyTests(BaseTestCase):
|
855 | 893 | def test_can_subclass(self):
|
|
0 commit comments