Skip to content

Confusing message if callable is incompatible due to argument name #4530

@JukkaL

Description

@JukkaL

Mypy generates a confusing error for this program:

from typing import Callable, Union
from mypy_extensions import Arg

def f(x: Callable[[Arg(int, 'x')], None]) -> None: pass

y: Callable[[Union[int, str]], None]
f(y)  # error

Here is the output:

t.py:7: error: Argument 1 to "f" has incompatible type "Callable[[Union[int, str]], None]"; expected "Callable[[int], None]"

The actual error is the missing argument name in the type of y, but the error message gives no hint about this.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions