Fix run_worker typing to support async def callables under mypy stric…#6604
Open
Arghyann wants to merge 1 commit into
Open
Fix run_worker typing to support async def callables under mypy stric…#6604Arghyann wants to merge 1 commit into
Arghyann wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR resolves issue #6386 by updating the
WorkTypetype alias and overloadingrun_workeronDOMNodeto preventmypytype-inference failures when passingasync defcallables.Root Cause:
In strict mode,
mypytype-checksasync deffunctions as returningCoroutine[Any, Any, ReturnType]. SinceWorkTypeoriginally requiredCoroutine[None, None, ReturnType], it failed. Simply wideningWorkTypetoCoroutine[Any, Any, ResultType]is insufficient becausemypy's generic type inference conflicts when matching a callable return type against bothCallable[[], Coroutine[Any, Any, ResultType]]andCallable[[], ResultType], causing it to inferResultTypeasNever.Fix:
WorkTypeto acceptCoroutine[Any, Any, ResultType]instead ofCoroutine[None, None, ResultType].@overloadsignatures forrun_workerinDOMNodeto evaluate the callable/awaitable structures independently.run_workerimplementation signature to acceptWorkType[Any]and returnWorker[Any]to allow the overloads to drive the external type-checking.Link to issue or discussion
Fixes #6386
Testing
mypychecking passes on user reproduction files.pytest tests/workers/and verified they pass successfully.