Skip to content

Fix set annotations in concurrent.futures._base #6034

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

Merged
merged 2 commits into from
Sep 14, 2021
Merged
Changes from all 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
12 changes: 6 additions & 6 deletions stdlib/concurrent/futures/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import sys
import threading
from _typeshed import Self
from abc import abstractmethod
from collections.abc import Container, Iterable, Iterator, Sequence, Set
from collections.abc import Container, Iterable, Iterator, Sequence
from logging import Logger
from typing import Any, Callable, Generic, Protocol, TypeVar, overload
from typing import Any, Callable, Generic, Protocol, Set, TypeVar, overload

if sys.version_info >= (3, 9):
from types import GenericAlias
Expand Down Expand Up @@ -76,12 +76,12 @@ def as_completed(fs: Iterable[Future[_T]], timeout: float | None = ...) -> Itera

# Ideally this would be a namedtuple, but mypy doesn't support generic tuple types. See #1976
class DoneAndNotDoneFutures(Sequence[Set[Future[_T]]]):
done: Set[Future[_T]]
not_done: Set[Future[_T]]
def __new__(_cls, done: Set[Future[_T]], not_done: Set[Future[_T]]) -> DoneAndNotDoneFutures[_T]: ...
done: set[Future[_T]]
not_done: set[Future[_T]]
def __new__(_cls, done: set[Future[_T]], not_done: set[Future[_T]]) -> DoneAndNotDoneFutures[_T]: ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should done and not_done be mutable, so that users can add or remove futures from them? collections.abc.Set is immutable and would prevent that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They are set in the implementation and mutable.

def __len__(self) -> int: ...
@overload
def __getitem__(self, i: int) -> Set[Future[_T]]: ...
def __getitem__(self, i: int) -> set[Future[_T]]: ...
@overload
def __getitem__(self, s: slice) -> DoneAndNotDoneFutures[_T]: ...

Expand Down