Skip to content

Fix Task.__call__ return value typing - #1091

Open
saitakarcesme wants to merge 1 commit into
pyinvoke:2.2from
saitakarcesme:codex/task-call-return-type
Open

saitakarcesme wants to merge 1 commit into
pyinvoke:2.2from
saitakarcesme:codex/task-call-return-type

Conversation

@saitakarcesme

Copy link
Copy Markdown

Fixes #1073.

Calling a concretely annotated Task[Callable[[Context], int]] currently produces a callable type instead of int. Bind a separate return type through __call__'s annotated self parameter, preserving the existing single-parameter Task[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 @task decorator 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 Any result cannot make the test pass. Include a changelog entry. Based on 2.2, following the contribution guide's maintenance-branch guidance (the report reproduces on 2.2.1).

Validation on macOS / Python 3.13.5:

  • Regression fails on the unchanged source and passes with the fix.
  • Full unit suite in a real TTY with --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.
  • Regression passes with mypy 2.3.1, and with the repository-pinned 0.971 on Python 3.11.16.
  • Pinned mypy + pinned PyYAML stubs: all 48 package source files pass.
  • Pinned Black 22.8.0 (line length 79), flake8, and git diff --check pass 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant