ty
ty copied to clipboard
support externally patching methods on instances
Initially reported at https://github.com/astral-sh/ty/issues/2134
We should support patching a method on an instance, if the replacement has compatible signature.
https://play.ty.dev/80fd5a68-8c7d-4e73-b5e8-6906a9f9bf61
class RateLimiter:
def check_limit(self) -> bool:
return True
def test_lambda_stub_method():
rl = RateLimiter()
# Common pattern: stub method with lambda to control return value
rl.check_limit = lambda: False # ty: invalid-assignment
#350 is also somewhat related
I think @sharkdp previously did experiments around this. Possibly in https://github.com/astral-sh/ruff/pull/18275?