warn when default values on overloads differ from implementation signature
Open
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 foo(value1: str, value2: bool = False) -> str: # this default value is wrong/useless
...
@overload
def foo(value1: int, value2: bool = False) -> int: # this default value is wrong/useless
...
def foo(value1: str | int, value2: bool = True) -> str | int:
...
in fact, maybe even prohibit defaults on overload signatures entirely, like in typescript:
function foo(value1: number, value2: boolean = false): number //error: A parameter initializer is only allowed in a function or constructor implementation.
function foo(value1: string, value2: boolean = false): string //error: A parameter initializer is only allowed in a function or constructor implementation.
function foo(value1: number | string, value2: boolean = true): number | string {
return 1
}
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 by reproducing the overload example and trace mypy's overload-signature checking. Determine whether the accepted behavior should be a warning for defaults that differ from the implementation or an error for any defaults on overloads. Done means the chosen rule is enforced consistently and covered by regression tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100