Closed wchresta closed 3 years ago
Providing match with functions with explicit signatures type checks:
def _0ary_const_none() -> None:
return None
def _1ary_id(a: int) -> int:
return a
def _2ary_const_none(a: str, b: str) -> None:
return None
@adt
class ExampleADT:
EMPTY: Case
INTEGER: Case[int]
STRING_PAIR: Case[str, str]
@property
def explicit_safe_integer(self) -> Optional[int]:
return self.match(empty=_0ary_const_none,
integer=_1ary_id,
string_pair=_2ary_const_none)
This might be a weakness in (or a misunderstanding on our part of) mypy
's reasoning about of type variables.
When running
mypy==0.711
against the following code taken from theREADME
, mypy throws an error: