example-code-2e/13-protocol-abc/double/double_protocol.py
2021-02-14 20:58:46 -03:00

12 lines
247 B
Python

from typing import TypeVar, Protocol
T = TypeVar('T') # <1>
class Repeatable(Protocol):
def __mul__(self: T, repeat_count: int) -> T: ... # <2>
RT = TypeVar('RT', bound=Repeatable) # <3>
def double(x: RT) -> RT: # <4>
return x * 2