Datasets:
File size: 1,066 Bytes
d8a7ddd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | """
Tests the handling of modules as the implementation of a protocol.
"""
# Specification: https://typing.readthedocs.io/en/latest/spec/protocol.html#modules-as-implementations-of-protocols
# > A module object is accepted where a protocol is expected if the public
# > interface of the given module is compatible with the expected protocol.
import _protocols_modules1
import _protocols_modules2
from typing import Protocol
class Options1(Protocol):
timeout: int
one_flag: bool
other_flag: bool
class Options2(Protocol):
timeout: str
op1: Options1 = _protocols_modules1 # OK
op2: Options2 = _protocols_modules1 # E
class Reporter1(Protocol):
def on_error(self, x: int) -> None:
...
def on_success(self) -> None:
...
class Reporter2(Protocol):
def on_error(self, x: int) -> int:
...
class Reporter3(Protocol):
def not_implemented(self, x: int) -> int:
...
rp1: Reporter1 = _protocols_modules2 # OK
rp2: Reporter2 = _protocols_modules2 # E
rp3: Reporter3 = _protocols_modules2 # E
|