Skip to content

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

@thepabloaguilar

Description

@thepabloaguilar

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy