-
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
this builds upon #97
additionally allow Protocol
s with only __call__
implemented and @type_check_only
as the only class decorator
if the protocol is generic, then all params must be bound (or have a default), because these will
be substituted into the inlined method
it will be inlined into some class as method, when accessed as e.g.
from typing import Protocol, type_check_only
__all__ = ["A"]
@type_check_only
class _IOpMethod[OtherT](Protocol):
def __call__[SelfT](self, lhs: SelfT, rhs: OtherT | SelfT, /) -> SelfT: ...
class A[T]:
__iadd__: _IOpMethod[T]
__isub__: _IOpMethod[T]
which results in something like
from typing import Protocol
from typing_extensions import Self
__all__ = ["A"]
class A[T]:
def __iadd__(self, rhs: T | Self, /) -> Self: ...
note that the lhs
param in _IOpMethod.__call__
was renamed to self
, and was stripped of its annotation (following the rules in #97)