-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
concurrent.futures: Bad signature for Executor.submit() under Python <= 3.8 #7750
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
Comments
Looking at the source in 3.8, Python still seems to accept |
I believe you meant "... as a KEYWORD argument". Did you notice the last line? Whether the current stub is correct or not is a bit open to debate. From the point of view of intention, looks like it is incorrect. However, the really pressing issue for me is to get mypy happy, otherwise I cannot typecheck my own code using |
It's hard to say what the right answer is because the method is abstract. However, the process pool executor does still accept Can you clarify why your code breaks? Are you creating your own executor? |
@JelleZijlstra Yes, I am subclassing the
So mypy's |
Note That in Python 3.8 we have the following signature override in the |
stubtest is a great tool, but it can have false positives. The implementation of |
I don't think this is a false positive. IMHO, it is actually spotting an bug/inconsistency in typeshed stubs.
Python 3.8 effectively replaces the signature of |
typeshed generally favors the implementation over documentation and the implementation in 3.8 still allows a keyword argument. But I also wonder why stubtest even complains about this, since the implementation uses |
stubtest complains because CPython sets I don't feel strongly, but I'd be okay changing this. At this point, it's probably valuable for users to know their code won't work on 3.9 and it looks like the associated CPython change was pushed through quickly and without too much pain (deprecated in 3.8, removed in 3.9). |
@hauntsaninja I tried using |
I'm a little confused about what exactly your use case is; e.g. I'm not sure what overload you're trying to add, or why it would need changes to mypy / stubtest. To be concrete, this is the change I thought we were discussing: diff --git a/stdlib/concurrent/futures/_base.pyi b/stdlib/concurrent/futures/_base.pyi
index 5b756d87..303383a3 100644
--- a/stdlib/concurrent/futures/_base.pyi
+++ b/stdlib/concurrent/futures/_base.pyi
@@ -60,11 +60,7 @@ class Future(Generic[_T]):
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
class Executor:
- if sys.version_info >= (3, 9):
- def submit(self, __fn: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> Future[_T]: ...
- else:
- def submit(self, fn: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> Future[_T]: ...
-
+ def submit(self, __fn: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> Future[_T]: ...
def map(
self, fn: Callable[..., _T], *iterables: Iterable[Any], timeout: float | None = ..., chunksize: int = ...
) -> Iterator[_T]: ... |
Your change is not correct for Python 3.7 (and 3.6, although I know it is EOL). Look at my original patch in the description, I believe that's the proper fix in order to support all the old Pythons Regarding overloads, I tried to special case 3.8 (using a |
Okay, I see. Yeah, I don't think overloads are a good solution here (subclasses would still break LSP, stubtest would still complain, both of those are probably desirable). Like I said in a previous message, I'd be fine with changing the version check. Also I can confirm that mypy will do the right thing with |
Where should I put the Please note I'm already using that comment in a But The warning I'm getting is not from my own code, but from the abstract I cannot add |
Reproducer
Tentative fix
The text was updated successfully, but these errors were encountered: