python / python/mypy

(🐞) Bad error message when invoking an overload with a bad call

Open
#13,343 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This sample produces two error messages, the second is completely valid, but the first makes no sense.

from typing import overload

@overload
def foo(a: list[int]): ...
@overload
def foo(a: list[object]): ...
def foo(a): ...

foo(dict[str, list[object]]()[1])
# Argument 1 to "foo" has incompatible type "list[object]"; expected "list[int]"
# Invalid index type "int" for "dict[str, list[object]]"; expected type "str"

playground

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 overload and invalid-dictionary-index reproducer, using the linked mypy-play example to observe both diagnostics. Trace how the overload call and invalid index are reported, then verify that the first message is no longer misleading while the valid index-type error remains. Add or update a regression test if the relevant test location is identified during investigation.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.