Skip to content

Commit 35bddd2

Browse files
Add asyncio.taskgroups and new Task methods (#7240)
Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent 5a8b9da commit 35bddd2

File tree

9 files changed

+28
-0
lines changed

9 files changed

+28
-0
lines changed

stdlib/VERSIONS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ asyncio.exceptions: 3.8-
6868
asyncio.format_helpers: 3.7-
6969
asyncio.runners: 3.7-
7070
asyncio.staggered: 3.8-
71+
asyncio.taskgroups: 3.11-
7172
asyncio.threads: 3.9-
7273
asyncio.trsock: 3.8-
7374
asyncore: 2.7-

stdlib/asyncio/__init__.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ if sys.version_info >= (3, 7):
107107
current_task as current_task,
108108
)
109109

110+
if sys.version_info >= (3, 11):
111+
from .taskgroups import TaskGroup as TaskGroup
112+
110113
DefaultEventLoopPolicy: type[AbstractEventLoopPolicy]
111114

112115
if sys.platform == "win32":

stdlib/asyncio/taskgroups.pyi

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This only exists in 3.11+. See VERSIONS.
2+
3+
from _typeshed import Self
4+
from types import TracebackType
5+
from typing import Any, Coroutine, Generator, TypeVar
6+
7+
from .tasks import Task
8+
9+
_T = TypeVar("_T")
10+
11+
class TaskGroup:
12+
def __init__(self, *, name: str | None = ...) -> None: ...
13+
def get_name(self) -> str: ...
14+
async def __aenter__(self: Self) -> Self: ...
15+
async def __aexit__(self, et: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None: ...
16+
def create_task(self, coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T]) -> Task[_T]: ...

stdlib/asyncio/tasks.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ class Task(Future[_T], Generic[_T]):
276276
def cancel(self, msg: Any | None = ...) -> bool: ...
277277
else:
278278
def cancel(self) -> bool: ...
279+
if sys.version_info >= (3, 11):
280+
def cancelling(self) -> bool: ...
281+
def uncancel(self) -> bool: ...
279282
if sys.version_info < (3, 9):
280283
@classmethod
281284
def current_task(cls, loop: AbstractEventLoop | None = ...) -> Task[Any] | None: ...

tests/stubtest_allowlists/py310.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ asyncio.Future.__init__ # Usually initialized from c object
4141
asyncio.Future._callbacks # Usually initialized from c object
4242
asyncio.futures.Future.__init__ # Usually initialized from c object
4343
asyncio.futures.Future._callbacks # Usually initialized from c object
44+
asyncio.taskgroups # Added in Python 3.11
4445
builtins.dict.get
4546
contextvars.Context.__init__ # Default C __init__ signature is wrong
4647
contextlib.AbstractAsyncContextManager.__class_getitem__

tests/stubtest_allowlists/py36.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ asyncio.staggered # Added in Python 3.8
1313
asyncio.threads # Added in Python 3.9
1414
asyncio.trsock # Added in Python 3.8
1515
asyncio.mixins # Added in Python 3.10
16+
asyncio.taskgroups # Added in Python 3.11
1617
builtins.str.maketrans
1718
cmath.log
1819
collections.AsyncGenerator.ag_await

tests/stubtest_allowlists/py37.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ asyncio.staggered # Added in Python 3.8
1313
asyncio.threads # Added in Python 3.9
1414
asyncio.trsock # Added in Python 3.8
1515
asyncio.mixins # Added in Python 3.10
16+
asyncio.taskgroups # Added in Python 3.11
1617
builtins.dict.get
1718
builtins.str.maketrans
1819
cmath.log

tests/stubtest_allowlists/py38.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ asyncio.futures.Future.__init__ # Usually initialized from c object
1818
asyncio.futures.Future._callbacks # Usually initialized from c object
1919
asyncio.threads # Added in Python 3.9
2020
asyncio.mixins # Added in Python 3.10
21+
asyncio.taskgroups # Added in Python 3.11
2122
builtins.dict.get
2223
collections.AsyncGenerator.ag_await
2324
collections.AsyncGenerator.ag_code

tests/stubtest_allowlists/py39.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ asyncio.Future._callbacks # Usually initialized from c object
2020
asyncio.futures.Future.__init__ # Usually initialized from c object
2121
asyncio.futures.Future._callbacks # Usually initialized from c object
2222
asyncio.mixins # Added in Python 3.10
23+
asyncio.taskgroups # Added in Python 3.11
2324
builtins.dict.get
2425
collections.AsyncGenerator.ag_await
2526
collections.AsyncGenerator.ag_code

0 commit comments

Comments
 (0)