python / python/mypy

(🎁) Warn when overload impl default value is incompatible with overload part default value

Open
#13,363 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

from typing import overload

@overload
def f(x: object): ...
@overload
def f(x: int = ...): ...

def f(x: object = ""): ...

While this code is type-safe, it's almost certainly a mistake. The default value of overload part 2 is never going to be met by the implementation.

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 by tracing mypy's overload-checking logic using the example in the issue, focusing on how overload-part and implementation default values are compared. Done means emitting a diagnostic when an overload default cannot be met by the implementation default, while preserving the shown type-safe case otherwise.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.