Improve Python SDK type checking with ty

Closed
AN
2mo ago
+193-47

Why

The Python SDK excluded generated models from ty, leaving schema-to-Python typing errors undetected. Upgrading to ty 0.0.82 also exposed type errors in Chrome process handling. Since generated models ship as part of the typed SDK, these issues can affect downstream type checking.

What

  • Upgrade and pin ty to 0.0.82, include generated Python in its checks, and enable selected stricter rules.
  • Generate validated model factories for dictionary defaults typed as Pydantic models. The generator detects these fields automatically, while leaving ordinary dictionary defaults alone.
  • Fix the Chrome process and return-type diagnostics, add required @override decorators, and run ty immediately after Python generation.
  • Add tests for generated defaults and for the generator’s model-field detection.

How

Verified with generate.py --check, ty, Ruff, the Python test suite (531 passed, 1 skipped), and just check.


Summary by cubic

Starts type-checking generated Python SDK models and upgrades and pins ty to 0.0.82. The generated models were previously excluded from ty, so schema-to-Python typing errors went undetected and could affect downstream type checking.

  • Enables stricter ty rules for override enforcement and return handling.
  • Rewrites Pydantic-typed dictionary defaults in generated code as model factories so defaults keep their declared types and wire values; plain dict defaults are unchanged.
  • Fixes the Chrome process and return-type diagnostics exposed by the stricter rules.
  • Adds required @override decorators and typing_extensions as a runtime dependency.
  • Runs ty as part of just generate.
  • Adds tests for generated defaults and the generator’s model-field detection.