Skip to content

(🐞) Wrong error message on overloaded function with unexpected keyword parameter #11927

@KotlinIsland

Description

@KotlinIsland

No overload variant of "foo" matches argument type "int"

This error message is flat out incorrect as there is a variant that matches int but there is an unexpected parameter name.

from typing import overload

@overload
def foo(a: int) -> None: ...

@overload
def foo(a: str) -> None: ...

def foo(a: object) -> None: ...

def bar(a: int) -> None: ...

foo(b=1)
bar(b=1)
main.py:11: note: "bar" defined here
main.py:13: error: No overload variant of "foo" matches argument type "int"  [call-overload]
main.py:13: note: Possible overload variants:
main.py:13: note:     def foo(a: int) -> None
main.py:13: note:     def foo(a: str) -> None
main.py:14: error: Unexpected keyword argument "b" for "bar"  [call-arg]
Found 2 errors in 1 file (checked 1 source file)

playground link

Also

In that output, for what reason is there a random main.py:11: note: "bar" defined here? Should I raise that as a separate issue?

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions