Skip to content

Fix Python SDK type issues with ty type checker#1122

Merged
mishushakov merged 22 commits intomainfrom
mishushakov/fix-ty-type-errors
Feb 12, 2026
Merged

Fix Python SDK type issues with ty type checker#1122
mishushakov merged 22 commits intomainfrom
mishushakov/fix-ty-type-errors

Conversation

@mishushakov
Copy link
Copy Markdown
Member

@mishushakov mishushakov commented Feb 9, 2026

Summary

  • Resolved 43 type diagnostics reported by ty (Astral's Python type checker)
  • Fixed Self type issues on class singletons
  • Added explicit type annotations for shadowed attributes
  • Replaced None with UNSET for auto-generated API parameters
  • Fixed method signature alignment for protocol matching
  • Added targeted type: ignore suppressions for pattern-based limitations

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


Note

Medium Risk
Mostly typing/CI changes, but some adjustments affect sandbox connect/pause overload dispatch and API response/parameter handling (UNSET vs None), which could alter edge-case runtime behavior.

Overview
Fixes Python SDK static typing issues for Astral’s ty checker and wires typechecking into CI.

Adds a new Typecheck GitHub Action plus workspace typecheck scripts (TS packages via tsc, Python SDK via make typecheck running ty), and publishes a patch changeset for @e2b/python-sdk.

Across the Python SDK, adjusts type annotations and overloads (e.g., Self/singleton typing, connect overloads, optional user/token/domain handling), tightens API model parsing with cast/Optional checks and UNSET usage, and adds a few targeted ty ignore comments in tests/protocols to silence checker limitations.

Written by Cursor Bugbot for commit f664028. This will update automatically on new commits. Configure here.

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>
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 9, 2026

🦋 Changeset detected

Latest commit: f664028

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@e2b/python-sdk Patch

Not sure what this means? Click here to learn what changesets are.

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

mishushakov and others added 7 commits February 9, 2026 14:22
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>
},
headers=headers,
token=token,
token=token or "",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is fine

self._headers[self.auth_header_name] = (
f"{self.prefix} {self.token}" if self.prefix else self.token
)

mishushakov and others added 7 commits February 9, 2026 16:01
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>
Comment thread .github/workflows/typecheck.yml Fixed
mishushakov and others added 3 commits February 9, 2026 17:03
…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>
@mishushakov mishushakov marked this pull request as ready for review February 9, 2026 18:03
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Comment thread packages/python-sdk/e2b/sandbox_async/sandbox_api.py Outdated
Comment thread packages/python-sdk/e2b/connection_config.py Outdated
Revert `mcp` from `is not None` check back to truthiness check so
empty dicts are treated as UNSET. Remove unnecessary local alias in
get_sandbox_url and use self._sandbox_url directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mishushakov mishushakov force-pushed the mishushakov/fix-ty-type-errors branch from 5b8435b to be1f50b Compare February 10, 2026 14:46
Copy link
Copy Markdown
Contributor

@matthewlouisbrockman matthewlouisbrockman left a comment

Choose a reason for hiding this comment

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

more typechecking! seems like not issues to me

@mishushakov mishushakov enabled auto-merge (squash) February 12, 2026 15:59
@mishushakov mishushakov merged commit c38a181 into main Feb 12, 2026
18 of 19 checks passed
@mishushakov mishushakov deleted the mishushakov/fix-ty-type-errors branch February 12, 2026 16:23
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.

3 participants