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

concurrent.futures.wait should return a NamedTuple #3380

Closed
Phlogistique opened this issue Oct 17, 2019 · 2 comments
Closed

concurrent.futures.wait should return a NamedTuple #3380

Phlogistique opened this issue Oct 17, 2019 · 2 comments
Labels
stubs: false positive Type checkers report false errors

Comments

@Phlogistique
Copy link

Phlogistique commented Oct 17, 2019

Currently, the type of concurrent.futures.wait in typeshed is as follows:

def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: str = ...) -> Tuple[Set[Future[_T]],
                                                                                                    Set[Future[_T]]]: ...

According to Python's documentation:

Returns a named 2-tuple of sets. The first set, named done, contains the futures that completed (finished or cancelled futures) before the wait completed. The second set, named not_done, contains the futures that did not complete (pending or running futures).

So the type should really be:

class DoneAndNotDoneFutures(Generic[_T], NamedTuple):
    done: Set[Future[_T]]
    not_done: Set[Future[_T]]

def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: str = ...) -> DoneAndNotDoneFutures[_T]: ...

(the name of the NamedTuple is taken from CPython's implementation of concurrent.futures)

Unfortunately, generic NamedTuples are not currently supported by mypy, so that change would break the tests.

@srittau
Copy link
Collaborator

srittau commented Oct 17, 2019

Thank you for the good analysis. PR welcome!

@JelleZijlstra
Copy link
Member

Duplicate of #1976.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false positive Type checkers report false errors
Projects
None yet
Development

No branches or pull requests

3 participants