Skip to content

app without a task type specializes to Task[P, R] - #227

Merged
kodiakhq[bot] merged 3 commits into
sbdchd:mainfrom
jgarst:celery-app-task-base
Jul 23, 2026
Merged

app without a task type specializes to Task[P, R]#227
kodiakhq[bot] merged 3 commits into
sbdchd:mainfrom
jgarst:celery-app-task-base

Conversation

@jgarst

@jgarst jgarst commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

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]. 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 self Celery type annotation matches the non-generic default Celery[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.

@jgarst
jgarst force-pushed the celery-app-task-base branch from 5070f5f to effedea Compare July 21, 2026 14:42
@jgarst

jgarst commented Jul 21, 2026

Copy link
Copy Markdown
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.

jgarst added 3 commits July 22, 2026 17:31
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
jgarst force-pushed the celery-app-task-base branch from effedea to 06d1c39 Compare July 23, 2026 02:26
@jgarst

jgarst commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Updated ty, waffled on whether to split the bump into a separate PR but ultimately included it as a separate commit.

@sbdchd sbdchd left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this!

@sbdchd sbdchd added the automerge auto merge PRs using kodiak label Jul 23, 2026
@kodiakhq
kodiakhq Bot merged commit 9408e3c into sbdchd:main Jul 23, 2026
2 checks passed
@jgarst
jgarst deleted the celery-app-task-base branch July 28, 2026 02:25
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge auto merge PRs using kodiak

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants