Fix Task.__call__ return value typing - #1091
Open
saitakarcesme wants to merge 1 commit into
Open
saitakarcesme wants to merge 1 commit into
saitakarcesme 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.
Fixes #1073.
Calling a concretely annotated
Task[Callable[[Context], int]]currently produces a callable type instead ofint. Bind a separate return type through__call__'s annotated self parameter, preserving the existing single-parameterTask[Callable[...]]API and runtime behavior. The callable type parameter is covariant so callable-object types also work with that self annotation. This does not change the@taskdecorator signature or attempt #1067; open PR #956 changes that decorator but does not address this method.Add a mypy regression covering int, str, None, optional values, callable objects and callable return values. Incorrect result assignments must still produce errors, so an accidental
Anyresult cannot make the test pass. Include a changelog entry. Based on2.2, following the contribution guide's maintenance-branch guidance (the report reproduces on 2.2.1).Validation on macOS / Python 3.13.5:
--capture=no: 969 passed, 11 skipped. Initial redirected/captured runs failed terminal-dependent tests; the documented no-capture mode with terminal stdin/stdout resolves those failures.git diff --checkpass for changed Python files.AI disclosure: implemented and tested by OpenAI Codex at the account owner's request. No claim of independent human code review.