Summary
ty rejects matching protocols if a dunder method doesn't restrict itself to position-only arguments. This is fine, but the error message is rather hard to work out:
from typing import Any, Protocol, runtime_checkable
@runtime_checkable
class WithSlash(Protocol):
def __getitem__(self, key: Any, /) -> Any: ...
@runtime_checkable
class NoSlash(Protocol):
def __getitem__(self, key: Any) -> Any: ...
a: WithSlash = {1: 2} # No error
b: NoSlash = {1: 2} # error[invalid-assignment]: Object of type `dict[Unknown | int, Unknown | int]` is not assignable to `NoSlash`
assert(isinstance(a, WithSlash)) # True
assert(isinstance(b, NoSlash)) # True
It'd be nice if ty (or perhaps ruff) checked for special dunder method declarations that do not match the necessary format, or had some other way of making this error clearer (or even accepting it as-is).
Version
ty 0.0.14 (16597f5 2026-01-26)
Summary
ty rejects matching protocols if a dunder method doesn't restrict itself to position-only arguments. This is fine, but the error message is rather hard to work out:
It'd be nice if ty (or perhaps ruff) checked for special dunder method declarations that do not match the necessary format, or had some other way of making this error clearer (or even accepting it as-is).
Version
ty 0.0.14 (16597f5 2026-01-26)