Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

mypy plugin: Example for safe_integer in README does not type-check. #26

Closed
wchresta opened this issue Dec 28, 2019 · 1 comment
Closed
Labels
bug Something isn't working mypy Relating to the ADT mypy plugin

Comments

@wchresta
Copy link
Collaborator

When running mypy==0.711 against the following code taken from the README, mypy throws an error:

@adt
class ExampleADT:
    EMPTY: Case
    INTEGER: Case[int]
    STRING_PAIR: Case[str, str]

    @property
    def safe_integer(self) -> Optional[int]:
        return self.match(empty=lambda: None,
                          integer=lambda n: n,
                          string_pair=lambda a, b: None)
error: Incompatible return value type (got "None", expected "int")
error: Incompatible return value type (got "None", expected "int")
wchresta added a commit to wchresta/adt that referenced this issue Dec 28, 2019
* Add test cases for issues jspahrsummers#21, jspahrsummers#25, jspahrsummers#26
* Test case for jspahrsummers#21 is active because it passes with mypy==0.711
* Test cases for jspahrsummers#25 and jspahrsummers#26 are deactivated because they fail
wchresta added a commit to wchresta/adt that referenced this issue Dec 28, 2019
* Add test cases for issues jspahrsummers#21, jspahrsummers#25, jspahrsummers#26
* Test case for jspahrsummers#21 is active because it passes with mypy==0.711
* Test cases for jspahrsummers#25 and jspahrsummers#26 are deactivated because they fail
wchresta added a commit to wchresta/adt that referenced this issue Dec 28, 2019
* Add test cases for issues jspahrsummers#21, jspahrsummers#25, jspahrsummers#26
* Test case for jspahrsummers#21 is active because it passes with mypy==0.711
* Test cases for jspahrsummers#25 and jspahrsummers#26 are deactivated because they fail
@jspahrsummers jspahrsummers added bug Something isn't working mypy Relating to the ADT mypy plugin labels Dec 28, 2019
@wchresta
Copy link
Collaborator Author

wchresta commented Dec 29, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working mypy Relating to the ADT mypy plugin
Projects
None yet
Development

No branches or pull requests

2 participants