Skip to content

mypy does not work correctly with nested overloaded, raising has incompatible type overloaded function [arg-type] #9017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sobolevn opened this issue Jun 18, 2020 · 1 comment

Comments

@sobolevn
Copy link
Member

sobolevn commented Jun 18, 2020

  • Are you reporting a bug, or opening a feature request?

Bug.

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.

Reproduction link: https://github.com/sobolevn/mypy-bug-410

Here's what is going wrong. In returns we have a custom mypy plugin that create curry functions. It works like so:

from returns.curry import curry

@curry
def first(a: int, b: int) -> int:
    ...

@curry
def second(a: int, b: int, c: int) -> int:
    ...

reveal_type(first)
reveal_type(second)

It works perfectly fine:

example.py:11: note: Revealed type is 'Overload(def (a: builtins.int) -> def (b: builtins.int) -> builtins.int, def (a: builtins.int, b: builtins.int) -> builtins.int)'
example.py:12: note: Revealed type is 'Overload(def (a: builtins.int) -> Overload(def (b: builtins.int, c: builtins.int) -> builtins.int, def (b: builtins.int) -> def (c: builtins.int) -> builtins.int), def (a: builtins.int, b: builtins.int) -> def (c: builtins.int) -> builtins.int, def (a: builtins.int, b: builtins.int, c: builtins.int) -> builtins.int)'

Ok, here's the next step. I try to pass both first and second functions as values to be wrapped by some other type:

class Result(Generic[_ValueType]):
    @classmethod
    def from_value(self, inner_value: _ValueType) -> 'Result[_ValueType]':
        return Result(inner_value)

reveal_type(
    Result.from_value(first),
)
reveal_type(
    Result.from_value(second),
)

And here's the problem, first works:

example.py:23: note: Revealed type is 'example.Result[Overload(def (a: builtins.int) -> def (b: builtins.int) -> builtins.int, def (a: builtins.int, b: builtins.int) -> builtins.int)]'

While second does not:

example.py:35: note: Revealed type is 'example.Result[Overload(def (a: builtins.int) -> Overload(def (b: builtins.int, c: builtins.int) -> builtins.int, def (b: builtins.int) -> def (c: builtins.int) -> builtins.int), def (a: builtins.int, b: builtins.int) -> def (c: builtins.int) -> builtins.int, def (a: builtins.int, b: builtins.int, c: builtins.int) -> builtins.int)]'
example.py:35: error: Argument 1 to "from_value" of "Result" has incompatible type overloaded function; expected overloaded function  [arg-type]

This part looks like an issue with mypy to me:

example.py:35: error: Argument 1 to "from_value" of "Result" has incompatible type overloaded function; expected overloaded function  [arg-type]

Build output: https://github.com/sobolevn/mypy-bug-410/runs/783959567?check_suite_focus=true#step:5:12

  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?

[email protected], other version like 0.770 are also affected
python: 3.6, 3.7, 3.8

  • What are the mypy flags you are using? (For example --strict-optional)

Full list is in the reproduction repo, here: https://github.com/sobolevn/mypy-bug-410/blob/master/setup.cfg#L2

Related:

@sobolevn
Copy link
Member Author

Duplicate of #8978

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant