python / python/mypy

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

Open
#11,927 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-error-reporting topic-overloads
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied main.py reproducer or the linked mypy playground and compare the diagnostics for overloaded foo with non-overloaded bar. Trace the overload error-reporting path and verify that the completed behavior distinguishes an unexpected keyword from an argument-type mismatch, while checking the unrelated bar definition note shown in the same output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.