Skip to content

Commit 14ab089

Browse files
authored
Use a generic NamedTuple for concurrent.futures.DoneAndNotDoneFutures (#9772)
1 parent 4273a83 commit 14ab089

1 file changed

Lines changed: 6 additions & 17 deletions

File tree

stdlib/concurrent/futures/_base.pyi

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import sys
22
import threading
33
from _typeshed import Unused
4-
from collections.abc import Callable, Iterable, Iterator, Sequence
4+
from collections.abc import Callable, Iterable, Iterator
55
from logging import Logger
66
from types import TracebackType
7-
from typing import Any, Generic, TypeVar, overload
8-
from typing_extensions import Literal, ParamSpec, Self, SupportsIndex
7+
from typing import Any, Generic, NamedTuple, TypeVar
8+
from typing_extensions import Literal, ParamSpec, Self
99

1010
if sys.version_info >= (3, 9):
1111
from types import GenericAlias
@@ -69,20 +69,9 @@ class Executor:
6969

7070
def as_completed(fs: Iterable[Future[_T]], timeout: float | None = None) -> Iterator[Future[_T]]: ...
7171

72-
# Ideally this would be a namedtuple, but mypy doesn't support generic tuple types. See #1976
73-
class DoneAndNotDoneFutures(Sequence[set[Future[_T]]]):
74-
if sys.version_info >= (3, 10):
75-
__match_args__ = ("done", "not_done")
76-
@property
77-
def done(self) -> set[Future[_T]]: ...
78-
@property
79-
def not_done(self) -> set[Future[_T]]: ...
80-
def __new__(_cls, done: set[Future[_T]], not_done: set[Future[_T]]) -> DoneAndNotDoneFutures[_T]: ...
81-
def __len__(self) -> int: ...
82-
@overload
83-
def __getitem__(self, __i: SupportsIndex) -> set[Future[_T]]: ...
84-
@overload
85-
def __getitem__(self, __s: slice) -> DoneAndNotDoneFutures[_T]: ...
72+
class DoneAndNotDoneFutures(NamedTuple, Generic[_T]):
73+
done: set[Future[_T]]
74+
not_done: set[Future[_T]]
8675

8776
def wait(
8877
fs: Iterable[Future[_T]], timeout: float | None = None, return_when: str = "ALL_COMPLETED"

0 commit comments

Comments
 (0)