Skip to content

Type checking problem with overloaded function, higher order function and typevar values #496

Closed
@JukkaL

Description

@JukkaL

Mypy complains about the following code even though it should be valid:

from typing import typevar, overload, Function

T = typevar('T', values=(int, str))
def f(x: T) -> None:
     m(g, x)  # Error: Argument 1 to "m" has incompatible type functionlike; expected Function[["str"] -> "int"]

A = typevar('A')
R = typevar('R')
def m(f: Function[[A], R], it: A) -> None: pass

@overload
def g(x: int) -> int: return x
@overload
def g(x: str) -> str: return x

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions