Skip to content
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

Mypy plugin generates incompatible type overloads for @curry decorated functions with TypeVar #1071

Open
fadedDexofan opened this issue Sep 16, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@fadedDexofan
Copy link

Bug report

What's wrong

returns mypy plugin generate incorrect type overloads for curry decorated function with TypeVar arguments

Code to reproduce issue:

from typing import TypeVar

from returns.curry import curry
from returns.io import IO

_T = TypeVar('_T', int, str)

@curry
def _union_sets(first_set: set[_T], second_set: set[_T]) -> set[_T]:
    return first_set.union(second_set)
    
@curry
def _concat_objs(first: _T, second: _T) -> _T:
    return first + second

set_1 = IO({1, 2, 3})
set_2 = IO({3, 4, 5})

union = set_1.apply(set_2.apply(IO(_union_sets)))

string_1 = IO('a')
string_2 = IO('b')

concat = string_1.apply(string_2.apply(IO(_concat_objs)))

Mypy gives incompatible type overloaded function error for both curried functions:

error: Argument 1 to "IO" has incompatible type overloaded function; expected "Callable[[Set[int]], Callable[..., Set[_T]]]"  [arg-type]
error: Argument 1 to "IO" has incompatible type overloaded function; expected "Callable[[Set[int]], Callable[[Set[int]], Set[_T]]]"  [arg-type]
error: Argument 1 to "IO" has incompatible type overloaded function; expected "Callable[[str], Callable[..., _T]]"  [arg-type]
error: Argument 1 to "IO" has incompatible type overloaded function; expected "Callable[[str], Callable[[str], _T]]"  [arg-type]

How is that should be

Type overloads for functions with TypeVar's should be generated correctly

System information

  • python version: 3.9.7

  • returns version: 0.16.0

  • mypy version: 0.910

  • hypothesis version (if any):

  • pytest version (if any):

@fadedDexofan fadedDexofan added the bug Something isn't working label Sep 16, 2021
@fadedDexofan fadedDexofan changed the title Plugin generates incompatible type overloads for @curry decorated functions with TypeVar Mypy plugin generates incompatible type overloads for @curry decorated functions with TypeVar Sep 16, 2021
@fadedDexofan
Copy link
Author

Found that error disappears if add type annotation to result var.
E.g.

union: IO[set[int]] = set_1.apply(set_2.apply(IO(_union_sets)))
concat: IO[set[str]] = string_1.apply(string_2.apply(IO(_concat_objs)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

1 participant