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

Error to infer types from a curried function with more than two args #8978

Closed
thepabloaguilar opened this issue Jun 9, 2020 · 4 comments · Fixed by #9259
Closed

Error to infer types from a curried function with more than two args #8978

thepabloaguilar opened this issue Jun 9, 2020 · 4 comments · Fixed by #9259
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-overloads topic-type-variables

Comments

@thepabloaguilar
Copy link

This is possibly a BUG

I'm using returns lib that provide fully typed functions, it has a curry decorator. I'm trying to use it, but mypy has got an error when we have a curried function with more than two args and try to create a Result container with the function.

Result.from_value(...) source code
@curry source code

Working example:

from returns.curry import curry
from returns.result import Result

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

reveal_type(
    Result.from_value(first),
)
# Revealed type is 'returns.result.Result[Overload(def (a: builtins.int) -> def (b: builtins.int) -> builtins.int, def (a: builtins.int, b: builtins.int) -> builtins.int), Any]'

Nonworking example:

from returns.curry import curry
from returns.result import Result

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

reveal_type(
    Result.from_value(first),
)

mypy output:

ex.py:9: note: Revealed type is 'returns.result.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), Any]'
ex.py:9: error: Argument 1 to "from_value" of "Result" has incompatible type overloaded function; expected overloaded function
Found 1 error in 1 file (checked 1 source file)

Versions

  • mypy: 0.770
  • returns: 0.0.14
  • Python: 3.8.2

My config file:

[mypy]
# suppress errors about unsatisfied imports
ignore_missing_imports=True

# Custom plugins
plugins =
    returns.contrib.mypy.returns_plugin

# be strict
warn_return_any = True
strict_optional = True
warn_no_return = True
warn_redundant_casts = True
warn_unused_ignores = True
disallow_any_generics = True

disallow_untyped_defs = True
check_untyped_defs = True

# Temporally disabled
disallow_untyped_calls = False

Refs: dry-python/returns#410

@ilevkivskyi
Copy link
Member

Can you post a self-contained example? There is a known very old bug that generic functions when passed as arguments to another generic functions don't work.

@sobolevn
Copy link
Member

sobolevn commented Jun 18, 2020

Oups! I have posted a duplicate: #9017
But, I have also posted a reproduction link: https://github.com/sobolevn/mypy-bug-410

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 19, 2020

This looks like a bug, though it might plausibly be an issue with the returns plugin.

Using a complex overloaded function as a type variable doesn't seem to work in the example, even though it isn't generic.

@sobolevn
Copy link
Member

Oups, I forgot about this issue. I was able to find a hacky solution here: #9147

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-overloads topic-type-variables
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants