Skip to content

feat(typecheck): migrate from pyright to ty - #147

Merged
jwulf merged 4 commits into
mainfrom
feat/migrate-to-ty
May 28, 2026
Merged

jwulf merged 4 commits into
mainfrom
feat/migrate-to-ty

Conversation

@jwulf

@jwulf jwulf commented May 28, 2026 •

Copy link
Copy Markdown
Member

Closes #143. Stacked on top of #146 — merge #146 first.

Why

Migrate the project's type checker from pyright to ty (astral's new Python type checker, currently 0.0.40).

  • ~10–20× faster — uv run ty check runs in ~3 s versus 30–60 s for pyright on this repo. Big win for the inner-loop pre-commit / pre-push experience and for CI.
  • Toolchain alignment — we already use uv and ruff; ty is the same family.

What changed

1. feat(typecheck): migrate from pyright to ty

  • pyproject.toml: drop pyright dev-dep, add ty>=0.0.40; replace [tool.pyright] with [tool.ty.{environment,src,rules}] (extra-paths still includes generated/; src.exclude mirrors the previous pyright excludes).
  • Makefile: generate, generate-local, typecheck, typecheck-examples all invoke uv run ty check instead of uv run pyright.
  • scripts/setup-hooks.sh: comment-only refresh (the hook itself just runs make check, so the swap flows through automatically).
  • Docs (AGENTS.md, MAINTAINER.md, CONTRIBUTING.md, README.md, .github/prompts/): command references updated.

Real type fixes ty surfaced (baseline 11 → 0 diagnostics)

  • runtime/backpressure.py — module-as-Protocol: hoist clock or _time_module into a module-level cast(_Clock, _time_module) constant. ty doesn't infer module-as-Protocol structural compatibility automatically the way pyright did.
  • runtime/job_worker.py:
    • Drop the redundant cast in _determine_strategy: ty narrows EXECUTION_STRATEGY correctly after the != "auto" check.
    • Cast the dict-narrowed action_data to Mapping[str, Any] before passing to JobCompletionRequestVariables.from_dict: ty's intersection with the attrs Top-type otherwise rejects it.
  • hooks/post_gen/0700_generate_semantic_types.py — drop unused # type: ignore.
  • tests/acceptance/test_job_worker.py — drop unused # type: ignore.
  • tests/acceptance/test_backpressure.py — convert # type: ignore[arg-type] to ty-aware # ty: ignore[invalid-argument-type] on the intentional invalid-Literal test.

2. chore: remove demo/ directory

The demo/ directory contained scratch material (week_1/week_2 benchmark scripts, v2 backpressure analysis) that wasn't part of the published SDK and wasn't maintained alongside the generator. Already excluded from both ruff and the type checker, so removal is risk-free. Also drops the now-redundant demo entries from [tool.ty.src.exclude] and [tool.ruff.extend-exclude].

3. chore(generation): regenerate SDK for ty migration

Mechanical regen following the runtime/ source fixes (which are copied into generated/.../runtime/ by hook 0300).

Out of scope / left for follow-up

  • The 52 inert # pyright: ignore[...] comments scattered across runtime/, tests/, hooks/, examples/. They're benign under ty (treated as plain comments) and remain useful for anyone running pyright on the published generated/ package, so they're left in place.
  • Hook 1100/1200 patterns that emit pyright-shaped suppressions in generated code: still work for both checkers, no change needed.

Verification

make generate   # full pipeline (ruff fmt → ruff check → ty check → ty check examples/ → pytest → readme sync)
make lint
make typecheck
make test

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

@jwulf
jwulf force-pushed the feat/migrate-to-ty branch from bb757b7 to 5437f89 Compare May 28, 2026 21:16
@jwulf
jwulf changed the base branch from main to fix/hook-1200-required-polymorphic-list-todict May 28, 2026 21:16
@jwulf
jwulf changed the base branch from fix/hook-1200-required-polymorphic-list-todict to main May 28, 2026 21:39
@jwulf
jwulf requested a review from Copilot May 28, 2026 21:39
@jwulf jwulf self-assigned this May 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Migrates the repository’s type-checking tooling from pyright to Astral’s ty, updating configuration, build commands, docs, and applying a small set of typing-driven runtime/test fixes. This also removes the unmaintained demo/ tree and regenerates generated/stub outputs to match the new type-check baseline.

Changes:

  • Replace pyright with ty in dependencies, configuration (pyproject.toml), and build targets (Makefile).
  • Apply typing-driven fixes in runtime/ (and regenerated counterparts) and update ignore pragmas in tests/hooks.
  • Remove demo/ directory and update documentation/tooling references accordingly.

Reviewed changes

Copilot reviewed 79 out of 85 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
uv.lock Drops pyright (and nodeenv) from dev lock; adds ty locked to 0.0.40.
pyproject.toml Replaces [tool.pyright] with [tool.ty.*] configuration; adds ty to dev deps; removes demo from excludes.
Makefile Switches typecheck / generation pipeline type-check steps to uv run ty check (incl. examples/).
scripts/setup-hooks.sh Updates hook install comment to reference ty instead of pyright.
README.md Updates “Strict typing” claim to include ty compatibility.
AGENTS.md Updates developer docs to reference ty as the type-check gate/tool.
MAINTAINER.md Updates maintainer docs to reference ty for type-checking and related pipeline steps.
CONTRIBUTING.md Updates contributor docs to reference ty for type-checking.
.github/prompts/add-missing-examples.prompt.md Updates prompt instructions from pyright to ty.
runtime/backpressure.py Adds _DEFAULT_CLOCK cast to satisfy stricter type-checking; uses it as the default clock.
runtime/job_worker.py Removes redundant cast in strategy selection; adds Mapping cast for dict-based variables parsing.
hooks/post_gen/0700_generate_semantic_types.py Removes an unused type-ignore on an isinstance check.
tests/acceptance/test_job_worker.py Removes an unused # type: ignore on JobWorker construction.
tests/acceptance/test_backpressure.py Updates ignore pragma to ty-style suppression for an intentional invalid-Literal test.
generated/camunda_orchestration_sdk/runtime/backpressure.py Regenerated output reflecting the runtime/backpressure.py typing adjustment.
generated/camunda_orchestration_sdk/runtime/job_worker.py Regenerated output reflecting the runtime/job_worker.py typing adjustment.
stubs/camunda_orchestration_sdk/runtime/backpressure.pyi Stub regenerated to reflect _DEFAULT_CLOCK typing changes.
demo/week_2/test_api.py Removed demo artifact (directory cleanup).
demo/week_2/README.md Removed demo artifact (directory cleanup).
demo/week_2/pyproject.toml Removed demo artifact (directory cleanup).
demo/week_2/main.py Removed demo artifact (directory cleanup).
demo/week_2/loan-application-process.bpmn Removed demo artifact (directory cleanup).
demo/week_2/loan_workers.py Removed demo artifact (directory cleanup).
demo/week_2/frontend/styles.css Removed demo artifact (directory cleanup).
demo/week_2/frontend/SETUP.md Removed demo artifact (directory cleanup).
demo/week_2/frontend/README.md Removed demo artifact (directory cleanup).
demo/week_2/frontend/QUICKSTART.md Removed demo artifact (directory cleanup).
demo/week_2/frontend/index.html Removed demo artifact (directory cleanup).
demo/week_2/frontend/app.js Removed demo artifact (directory cleanup).
demo/week_2/deploy_loan_process.py Removed demo artifact (directory cleanup).
demo/week_2/camunda_demo_week2.egg-info/top_level.txt Removed demo artifact (directory cleanup).
demo/week_2/camunda_demo_week2.egg-info/SOURCES.txt Removed demo artifact (directory cleanup).
demo/week_2/camunda_demo_week2.egg-info/requires.txt Removed demo artifact (directory cleanup).
demo/week_2/camunda_demo_week2.egg-info/PKG-INFO Removed demo artifact (directory cleanup).
demo/week_2/camunda_demo_week2.egg-info/dependency_links.txt Removed demo artifact (directory cleanup).
demo/week_2/.env Removed demo artifact (directory cleanup).
demo/week_2/__init__.py Removed demo artifact (directory cleanup).
demo/week_1/subprocess_workload.py Removed demo artifact (directory cleanup).
demo/week_1/multicore_workload.py Removed demo artifact (directory cleanup).
demo/week_1/io_bound_workload.py Removed demo artifact (directory cleanup).
demo/week_1/demo.py Removed demo artifact (directory cleanup).
demo/week_1/cpu_bound_workload.py Removed demo artifact (directory cleanup).
demo/week_1/cancel_processes.py Removed demo artifact (directory cleanup).
demo/week_1/__init.py__ Removed demo artifact (directory cleanup).
demo/v2/scenarios/safety.json Removed demo artifact (directory cleanup).
demo/v2/scenarios/README.md Removed demo artifact (directory cleanup).
demo/v2/scenarios/quick.json Removed demo artifact (directory cleanup).
demo/v2/scenarios/minimal.json Removed demo artifact (directory cleanup).
demo/v2/scenarios/fast.json Removed demo artifact (directory cleanup).
demo/v2/scenarios/baseline.json Removed demo artifact (directory cleanup).
demo/v2/scenarios/.gitignore Removed demo artifact (directory cleanup).
demo/v2/run_fast_validation.sh Removed demo artifact (directory cleanup).
demo/v2/run_benchmark_scenarios.py Removed demo artifact (directory cleanup).
demo/v2/results/README.md Removed demo artifact (directory cleanup).
demo/v2/results/baseline_20251212_183413.json Removed demo artifact (directory cleanup).
demo/v2/resources/job_worker_load_test_process_1.bpmn Removed demo artifact (directory cleanup).
demo/v2/README.md Removed demo artifact (directory cleanup).
demo/v2/QUICK_START.md Removed demo artifact (directory cleanup).
demo/v2/job_worker_original.py Removed demo artifact (directory cleanup).
demo/v2/generate_benchmark_scenarios.py Removed demo artifact (directory cleanup).
demo/v2/BENCHMARK_GUIDE.md Removed demo artifact (directory cleanup).
demo/v2/backpressure/server_probe.py Removed demo artifact (directory cleanup).
demo/v2/backpressure/resources/bp-test-process.bpmn Removed demo artifact (directory cleanup).
demo/v2/backpressure/recompute_jain.py Removed demo artifact (directory cleanup).
demo/v2/backpressure/README.md Removed demo artifact (directory cleanup).
demo/v2/backpressure/evaluate.py Removed demo artifact (directory cleanup).
demo/v2/backpressure/compare_throughput.py Removed demo artifact (directory cleanup).
demo/v2/backpressure/compare_results.py Removed demo artifact (directory cleanup).
demo/v2/backpressure/compare_errors.py Removed demo artifact (directory cleanup).
demo/v2/backpressure/compare_50c.py Removed demo artifact (directory cleanup).
demo/v2/backpressure/analyze_results.py Removed demo artifact (directory cleanup).
demo/v2/backpressure/analyze_full_matrix.py Removed demo artifact (directory cleanup).
demo/v2/backpressure/analyze_floor.py Removed demo artifact (directory cleanup).
demo/v2/backpressure/analyze_completions.py Removed demo artifact (directory cleanup).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread runtime/backpressure.py Resolved
Comment thread runtime/backpressure.py Resolved
Comment thread MAINTAINER.md Resolved
jwulf and others added 4 commits May 29, 2026 09:55
Replace pyright with astral's ty (https://docs.astral.sh/ty/) as the
project's type checker. ty is ~10-20× faster (3.3s vs 30-60s on this
repo) and aligns with our existing astral toolchain (uv, ruff).

Changes:
- pyproject.toml: swap pyright dev-dep for ty; replace [tool.pyright]
  with [tool.ty.{environment,src,rules}]. extra-paths still includes
  generated/; src.exclude mirrors prior pyright excludes.
- Makefile: generate, generate-local, typecheck, typecheck-examples
  targets now invoke 'uv run ty check' instead of 'uv run pyright'.
- scripts/setup-hooks.sh: comment refresh.
- docs (AGENTS.md, MAINTAINER.md, CONTRIBUTING.md, README.md, prompts):
  command references updated.

Real type fixes surfaced by ty (resolving baseline 11 → 0 diagnostics):
- runtime/backpressure.py: hoist 'clock or _time_module' into a
  module-level cast(_Clock, _time_module) constant. ty doesn't infer
  module-as-Protocol compatibility automatically.
- runtime/job_worker.py: drop redundant cast in _determine_strategy
  (ty narrows EXECUTION_STRATEGY correctly after '!= "auto"'); cast
  the dict-narrowed action_data to Mapping[str, Any] before passing to
  JobCompletionRequestVariables.from_dict (ty's intersection with the
  attrs Top-type otherwise rejects it).
- hooks/post_gen/0700_generate_semantic_types.py: drop unused
  '# type: ignore'.
- tests/acceptance/test_job_worker.py: drop unused '# type: ignore'.
- tests/acceptance/test_backpressure.py: convert pyright-style
  '# type: ignore[arg-type]' to ty's '# ty: ignore[invalid-argument-type]'
  on the intentional invalid-Literal test.

Inert legacy '# pyright: ignore[...]' comments are left in place;
they're benign under ty (treated as plain comments) and useful for
anyone still running pyright on the generated output.

Refs: #143

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The demo/ directory contained scratch material (week_1/week_2 benchmark
scripts, v2 backpressure analysis) that's not part of the published SDK
or maintained alongside the generator. Removing it simplifies the
repository surface — and removes a large body of code that was excluded
from both ruff and the type checker anyway.

Also drops the now-redundant 'demo' entries from [tool.ty.src.exclude]
and [tool.ruff.extend-exclude].

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- runtime/backpressure.py (both sync + async managers): use
  'clock if clock is not None else _DEFAULT_CLOCK' instead of
  'clock or _DEFAULT_CLOCK', so a valid-but-falsy _Clock implementation
  isn't silently replaced by the default.
- hooks/post_gen/0700_generate_semantic_types.py: drop the dead
  'if not isinstance(schema, dict)' guard in _is_primitive_alias —
  the parameter is typed Dict[str, Any] and the call site already
  casts before calling.
- MAINTAINER.md: reference 'uv run ty check' instead of 'uvx ty check'
  so local results use the repo-pinned ty version from uv.lock.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Regenerated artifacts after the runtime/ + hook source fixes from
this branch (rebased on latest main). Also syncs uv.lock with the
post-release version bump on main.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jwulf
jwulf force-pushed the feat/migrate-to-ty branch from 5437f89 to d6ae7e4 Compare May 28, 2026 21:57
@jwulf
jwulf merged commit 26f41a3 into main May 28, 2026
20 checks passed
@jwulf
jwulf deleted the feat/migrate-to-ty branch May 28, 2026 23:49
@emilyoram emilyoram added the backport stable/9 Backport to stable/9 after merge label Dec 1, 2026
@emilyoram

Copy link
Copy Markdown
Collaborator

/backport

@camunda-sdk-automation

Copy link
Copy Markdown
Contributor

Created backport PR for stable/9:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-147-to-stable/9
git worktree add --checkout .worktree/backport-147-to-stable/9 backport-147-to-stable/9
cd .worktree/backport-147-to-stable/9
git reset --hard HEAD^
git cherry-pick -x bdcd7c63ceb74d82aca8397fead50cf36b65712b 0606bc126fa03c69e49c08b21646e3a0a291684e 3a2d417789f6b3854022842a5cdc061978b47b2f d6ae7e4189d986b9b35e232260a13f5eb5609234

camunda-sdk-automation Bot pushed a commit that referenced this pull request Dec 1, 2026
Cherry-picked from #147 onto stable/9 with conflicts. The conflict markers are committed as-is and must be resolved before this backport is merged.
emilyoram added a commit that referenced this pull request Dec 1, 2026
The demo/ directory holds scratch material (week_1/week_2 benchmark
scripts, v2 backpressure analysis) that is not part of the published SDK.
main removed it in #147; stable/9 still carried it, and once code scanning
started covering stable/9, its demo workers raised high-severity
py/clear-text-logging-sensitive-data alerts (#26-#29) for printing
simulated credit scores.

Also drops the now-redundant 'demo' entries from the ty and ruff excludes.

(cherry picked from commit 0606bc1)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
emilyoram added a commit that referenced this pull request Dec 1, 2026
The demo/ directory holds scratch material (week_1/week_2 benchmark
scripts, v2 backpressure analysis) that is not part of the published SDK.
main removed it as part of #147; stable/9 still carried it, and once code
scanning started covering stable/9, its demo workers raised high-severity
py/clear-text-logging-sensitive-data alerts (#26-#29) for printing
simulated credit scores.

Also drops the now-redundant 'demo' entries from the pyright and ruff
excludes. This backports only the demo removal from #147, not its
pyright-to-ty migration.

(cherry picked from commit 0606bc1)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
emilyoram added a commit that referenced this pull request Dec 1, 2026
* chore: remove demo/ directory (backport from #147 to stable/9)

The demo/ directory holds scratch material (week_1/week_2 benchmark
scripts, v2 backpressure analysis) that is not part of the published SDK.
main removed it as part of #147; stable/9 still carried it, and once code
scanning started covering stable/9, its demo workers raised high-severity
py/clear-text-logging-sensitive-data alerts (#26-#29) for printing
simulated credit scores.

Also drops the now-redundant 'demo' entries from the pyright and ruff
excludes. This backports only the demo removal from #147, not its
pyright-to-ty migration.

(cherry picked from commit 0606bc1)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* chore: add commitlint.config.cjs as on main and stable/10

demo/week_2/frontend/app.js was the only JavaScript file on stable/9.
CodeQL default setup analyses javascript-typescript repo-wide (main and
stable/10 have this config file), so without any JS on this branch its
JS analysis fails on every push, and the release security gate would
keep waiting for an analysis that never arrives. Carry the same
one-line config main and stable/10 have so the analysis has code.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Emily Oram <emily.oram@camunda.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport stable/9 Backport to stable/9 after merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use ty for typechecking

3 participants