Typo in kwarg to overloaded function results in message about type mismatch
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Passing an incorrectly named kwarg to an overloaded function results in a misleading error message about types:
from typing import overload
@overload
def foo(bar: int) -> int:
...
@overload
def foo(bar: None) -> None:
...
def foo(bar: int | None) -> int | None:
...
foo(baz=42) # typo: 'baz' should be 'bar'
error: No overload variant of "foo" matches argument type "int" [call-overload]
note: Possible overload variants:
note: def foo(bar: int) -> int
note: def foo(bar: None) -> None
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.10&gist=0c0b7a4699e67b65d38eb182fb75c444
Expected Behavior
A message such as error: Unexpected keyword argument "baz" for "foo" [call-arg] (which is what you get when the function is not overloaded).
Actual Behavior
error: No overload variant of "foo" matches argument type "int" [call-overload]
Your Environment
- Mypy version used: 1.0.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked mypy-play reproducer and trace overload call checking for keyword arguments. Add a regression test for the misspelled baz argument, then verify the diagnostic reports an unexpected keyword argument rather than an overload type mismatch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100