Skip to content

[codex] chore(typing): migrate python type checking to ty - #2882

Closed
hayescode wants to merge 1 commit into
mainfrom
codex/ty-migration
Closed

hayescode wants to merge 1 commit into
mainfrom
codex/ty-migration

Conversation

@hayescode

@hayescode hayescode commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • replace backend Python type checking from mypy/dmypy to Astral ty
  • update backend CI, contributor docs, and local scripts to use the new checker
  • remediate backend and test typing issues so ty check chainlit tests passes cleanly

Validation

  • pnpm run lint
  • cd backend && uv run pytest --cov=chainlit/
  • cd backend && uvx ty check chainlit tests --output-format concise
  • pnpm run buildUi

Notes

  • I staged only the Python type-checker migration files. The local worktree contains many unrelated frontend/Cypress edits that are intentionally not included in this PR.
  • Local Cypress/e2e could not be executed on this Windows machine because the cached Cypress.exe fails its own startup smoke test with:
    • bad option: --smoke-test
    • bad option: --ping=...
  • Because of that environment issue, pnpm test could not be used here to exercise the e2e job locally.

Summary by cubic

Switch backend Python type checking from mypy/dmypy to Astral ty. Updates CI, docs, configs, scripts, and code typing so ty passes cleanly, with small runtime-safe tweaks.

  • Migration

    • Type check with: uv run ty check chainlit tests.
    • Install extras with: uv sync --extra ty --extra tests --extra dev --extra custom-data.
    • Configure ty in pyproject.toml (tool.ty.src, environment.python-version, analysis.allowed-unresolved-imports, analysis.replace-imports-with-any).
    • CI: run ty check --output-format github; update setup steps and docs; package.json lintPython uses ty; drop .mypy_cache and backend/.dmypy.json from .gitignore.
  • Refactors

    • Typing fixes across backend and tests: use Sequence for widgets/tabs; make Message.content optional; default local_steps to []; narrow types in middleware/emitter/server; unify Step/LiteralAI step types; make session.client_type accept str.
    • Data/storage: remove type: ignore for boto3/GCS; cast clients; add runtime-safe GCS import alias; minor SQLAlchemy update to async_sessionmaker.
    • Runtime safety: guard Slack message lookups; add env_str in OAuth; cast middleware (CORSMiddleware, custom FastAPI middleware) where needed; expand MCP request types in server.
    • Elements/messages: tighten from_dict parsing and casts; small fixes in SDK callbacks (LangChain, LlamaIndex, OpenAI, Mistral).
    • Tests updated to reflect new types and optional fields.

Written for commit c8df17d. Summary will update on new commits.

@hayescode
hayescode force-pushed the codex/ty-migration branch from ea402a1 to 9a26f7e Compare April 7, 2026 19:27
Replace mypy/dmypy with Astral ty across backend tooling, CI, docs, and tests.\n\nValidation:\n- pnpm run lint\n- cd backend && uv run pytest --cov=chainlit/\n- cd backend && uvx ty check chainlit tests --output-format concise\n- pnpm run buildUi\n\nNote: local Cypress could not start on this Windows machine because the cached Cypress.exe fails its smoke test with 'bad option: --smoke-test'.\n\nCo-Authored-By: OpenAI Codex <noreply@openai.com>
@hayescode
hayescode force-pushed the codex/ty-migration branch from 9a26f7e to c8df17d Compare April 7, 2026 19:27
@asvishnyakov

Copy link
Copy Markdown
Member

Hi @hayescode! Thank you for the great contribution!

However, I have a few concerns:

  • Isn't ty still in early preview? I'd rather have full & correct type checking in Chainlit than a fast one.
  • I'd highly appreciate it if you updated this after refactor: dev scripts #2573, as it will introduce a single source of truth for linting, formatting, type checking, and other dev scripts - you'll literally only need to replace one line to switch mypy → ty.
  • AFAIK, Chainlit has a lot of missing types. I'd appreciate it if you took care of them in this PR or in a subsequent one.

@hayescode

Copy link
Copy Markdown
Contributor Author

Hi @hayescode! Thank you for the great contribution!

However, I have a few concerns:

  • Isn't ty still in early preview? I'd rather have full & correct type checking in Chainlit than a fast one.
  • I'd highly appreciate it if you updated this after refactor: dev scripts #2573, as it will introduce a single source of truth for linting, formatting, type checking, and other dev scripts - you'll literally only need to replace one line to switch mypy → ty.
  • AFAIK, Chainlit has a lot of missing types. I'd appreciate it if you took care of them in this PR or in a subsequent one.
  1. It's in beta since December. That's when I switched all of my products over and it has been working flawlessly and better than mypy, tbh, so it's not just speed.
  2. Ok i'll close this and wait for refactor: dev scripts #2573 although after next week i will be busy with work. When do you think that will be ready?
  3. I'll have to fix whatever ty finds to migrate.

@hayescode hayescode closed this Apr 7, 2026
@asvishnyakov

Copy link
Copy Markdown
Member

@hayescode I think it'll be ready within a few days - I'll do one or two more PRs with auto fixes (mostly formatting), which will shrink it down to ~30 files, and then I'll consider it ready for your 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.

2 participants