idiombench / Python /train /3.8 /protocol /modern_29.py
SwashBuckler001's picture
IdiomBench (part 10)
c6ed2d8 verified
Raw History Blame Contribute Delete
232 Bytes
class P(Protocol):
x: float
def f(arg: P) -> None:
arg.x = 0.42
class C:
x: int
c = C()
f(c) # Would typecheck if covariant subtyping
# of mutable attributes were allowed.
c.x >> 1 # But this fails at runtime