Skip to content

chore: replace ty type checker with basedpyright#1123

Closed
mishushakov wants to merge 18 commits intomainfrom
mishushakov/fix-ty-type-errors-v1
Closed

chore: replace ty type checker with basedpyright#1123
mishushakov wants to merge 18 commits intomainfrom
mishushakov/fix-ty-type-errors-v1

Conversation

@mishushakov
Copy link
Copy Markdown
Member

Summary

Migrate Python type checking from ty (v0.0.15) to basedpyright, a mature Pyright-based type checker. This replaces an immature type checker with a stable alternative that better handles Python patterns used in the codebase.

Changes

  • Replaced ty with basedpyright in dev dependencies
  • Updated pyproject.toml with basedpyright configuration (typeCheckingMode = "standard", excluding generated code)
  • Changed Makefile typecheck target from ty check to basedpyright
  • Fixed genuine type issues found by basedpyright (Unset type coercion, type annotations, narrowing)
  • Removed all ty-specific ignore comments from test files
  • TypeCheck now passes with 0 errors, 0 warnings across all packages

Test plan

  • All typecheck targets pass (pnpm run typecheck)
  • Linting passes (pnpm run lint)
  • Formatting applied (pnpm run format)

🤖 Generated with Claude Code

mishushakov and others added 18 commits February 9, 2026 14:17
Resolve 43 type diagnostics reported by ty (Astral's Python type checker). Changes include:
- Fixed Self type on class singletons to use concrete forward references
- Added explicit type annotations for instance attributes shadowing static methods
- Replaced None with UNSET sentinel for optional auto-generated API parameters
- Fixed protocol mismatches and method signatures to align types
- Added type: ignore suppressions for class_method_variant overload patterns and protocol structural subtyping edge cases

All checks pass: ty check, ruff format, ruff check.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
The @overload declarations mixing @staticmethod/@classmethod with regular
methods are fundamentally invalid in Python's type system. Remove them and
keep only the @class_method_variant implementation. The runtime behavior
(calling as both instance and class method) is unchanged via the descriptor.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix DockerfileParserInterface protocol: simplify copy.src to str
  (matching actual usage in parse_dockerfile), remove unused CopyItem import
- Fix metadata type: use cast(Dict[str, str], ...) for auto-generated
  Union[Unset, Any] field after isinstance narrowing
- Fix mcp type: use cast(Any, mcp) to bridge SDK McpServer type with
  auto-generated McpType0 (different representations of same data)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…d-override

The child classes' _cls_connect returns Self while the parent returns the
API Sandbox model. Renaming avoids the incompatible override.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract Unset isinstance checks into local variables for readability.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The downstream SandboxOpts types it as Optional[str] and checks
`is not None`, so an empty string would incorrectly pass through.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use self: str overloads to tell the type checker that methods like
Sandbox.kill("sandbox_id") and sandbox.kill() are both valid call
patterns. This avoids mixing @classmethod with instance method
overloads (which ty rejects as invalid-overload).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Switch from `self: str` overloads to `@classmethod` overloads so
basedpyright can resolve the class method variants. Configure ty
to ignore `invalid-overload` since the pattern is intentional.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Switch from @classmethod to @staticmethod on overloads to match the
original code. @staticmethod doesn't add cls parameter so the
parameter count stays consistent with the implementation, avoiding
basedpyright's reportInconsistentOverload.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The class_method_variant pattern (dual instance/static dispatch) is
inherently inexpressible in Python's type system, so the overload
implementation can never match the static overload signature.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add a CI workflow that runs type checking on PRs, mirroring the lint
workflow. Add typecheck scripts to all packages (tsc for JS/TS, ty for Python).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…in permissions

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
- Suppress no-matching-overload globally (ty bug with @staticmethod overloads)
- Add per-path overrides for generated API client models and protobuf stubs
- Add type annotations to test data dicts to fix union type inference
- Add inline ty:ignore for pytest.skip false positives
- Remove now-redundant inline suppression comments

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Migrate Python type checking from ty (v0.0.15) to basedpyright in standard mode. This replaces an immature type checker with a stable, Pyright-based alternative that better handles Python patterns used in the codebase.

Changes:
- Updated pyproject.toml with basedpyright configuration (typeCheckingMode = "standard", excluding generated code)
- Changed Makefile typecheck target from "ty check" to "basedpyright"
- Fixed genuine type issues:
  - Removed unused sandbox_url field from SandboxOpts TypedDict
  - Renamed _sandbox_url() method to _sandbox_url_env() to avoid name collision
  - Added Unset → None coercion for API response fields in AsyncSandbox and Sandbox
  - Fixed resolve_symlinks bool | None narrowing in template build
  - Initialized loop variables in test_write.py files
- Removed all ty-specific ignore comments from test files
- TypeCheck now passes with 0 errors, 0 warnings

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 9, 2026

⚠️ No Changeset found

Latest commit: b5868c6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@mishushakov mishushakov closed this Feb 9, 2026
@ValentaTomas ValentaTomas deleted the mishushakov/fix-ty-type-errors-v1 branch March 20, 2026 17:12
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.

1 participant