fix: resolve ty no-matching-overload on Sandbox.kill()#1119
Open
fix: resolve ty no-matching-overload on Sandbox.kill()#1119
Conversation
Make class_method_variant inherit from Generic[T] so that ty can track the decorated function's type through the descriptor. Without this, ty fails overload resolution for all methods using the class_method_variant pattern (kill, connect, set_timeout, get_info, get_metrics, beta_pause). Fixes ty error[no-matching-overload] while remaining compatible with mypy and pyright.
|
mishushakov
approved these changes
Feb 6, 2026
Member
|
add changeset and merge/release please |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tytype checker reportingerror[no-matching-overload]when callingSandbox.kill()(and all other methods using theclass_method_variantpattern)class_method_variantinherit fromGeneric[T]instead ofobjectProblem
The
class_method_variantdescriptor usescast(T, self)to tell type checkers that the decorator preserves the original function's type. WithoutGeneric[T],Tis only a method-level TypeVar —tydoesn't trust the cast and fails to resolve overloads at call sites.mypyandpyrightare more lenient and accept it either way.Affected methods (both
SandboxandAsyncSandbox):kill,connect,set_timeout,get_info,get_metrics,beta_pause.Fix
Adding
Generic[T]makesTa class-level type parameter, sotycan track the type binding through the descriptor (class_method_variant[(self, **opts) -> bool]). The cast then makes sense to all three type checkers.Verification
Tested with a consumer repro (
sandbox.kill()) against:error[no-matching-overload]Test plan
ty checkpasses on consumer-side repromypyandpyrightstill pass (no regressions)Generic[T]only affects type-level metadata)