app without a task type specializes to Task[P, R] - #227
Merged
Conversation
jgarst
force-pushed
the
celery-app-task-base
branch
from
July 21, 2026 14:42
5070f5f to
effedea
Compare
Contributor
Author
|
Upgrading ty seems to solve the test failures, but other tests catch stray errors from the upgrade. I'll take a look at upgrading, but probably won't get to it until later in the week. |
Python typing doesn't have higher kinded types, and so is not able to pass a generic task type T through to the task creation decorator methods @app.task with the full task signature T[P, R]. Commit 4cc92d7 made the Celery app generic, but regressed the annotations for the call parameters and return type because of this limitation. This change recovers the ability to pass a full task signature to the newly created task when there is no generic type by adding an overload to the task decorator methods for when the `self` Celery type annotation matches the non-generic default `Celery[Task]`
jgarst
force-pushed
the
celery-app-task-base
branch
from
July 23, 2026 02:26
effedea to
06d1c39
Compare
Contributor
Author
|
Updated |
kodiakhq Bot
pushed a commit
that referenced
this pull request
Jul 29, 2026
While turning around the [last PR](#227), I stubbed my toe on `ty` checks running in CI but not in pre-commit. [PR #212](#212) looks like it added the check, but not the local devtools or mention in the readme. This PR adds the ty type checker to the README, linting script, and pre-commit hooks, matching the requirements of the ci gate. I had this in my branches, but am a little ambivalent about further cementing `ty` as a supported type checker, because I ran into a confusing bug while using it. I compromised [by writing up the problem](#228), and being embarrassed about the wall of text. Can't win I guess.
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.
Python typing doesn't have higher kinded types, and so is not able to pass a generic task type
Tthrough to the task creation decorator methods @app.task with the full task signatureT[P, R]. PR #203 made the Celery app generic, but regressed annotations for the call parameters and return type because of this limitation.This change recovers the ability to pass a full task signature to the newly created task when there is no generic type by adding an overload to the task decorator methods for when the
selfCelery type annotation matches the non-generic defaultCelery[Task].Should address issue #223. I can't think of any way to sidestep the need for a
T[P, R]construction to annotate the generic case, so unless someone else comes up with something clever this might be the best that can be done without application authors writing affordances to specialize to concrete types in their own code.I've made some guesses about testing and documenting. I'm happy to write more, write less, split things out, or do something different - I don't have that many opinions myself.