More specific overlapping overload errors

Open
#3,819 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start by reproducing the supplied overload example with mypy and trace the existing diagnostic for incompatible overlapping overloads. Identify the overload-checking and error-reporting entry points; done means the diagnostic explains the overlapping call shapes, including the no-argument call, while preserving the existing incompatibility information.

Written by the indexing model from the issue text.

Description

feature priority-1-normal topic-overloads topic-usability

Again when wrapping my head around #3805, I was thrown off by the output of mypy against:

from typing import *

@overload
def f(arg: str = "foo") -> AbstractSet[Tuple[str, str]]: ...

@overload
def f(arg: int = 0) -> AbstractSet[Tuple[str, Tuple[str, int]]]: ...

which gives

test.pyi:4: error: Overloaded function signatures 1 and 2 overlap with incompatible return types

The problem here is that each overload can be called without arguments (but I didn't see this until an eagle-eyed BDFL pointed it out 😁).

It would be good if the error message could include a little more information about the ways in which the signatures overlap, to make fixing the error an easier experience.

Dominant language
Python
Stars
20.6k
Forks
3.3k
Avg merge
1d 18h
Merged PRs (30d)
54

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.

More from python/mypy

All issues in python/mypy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.