KotlinIsland / KotlinIsland/basedmypy
validate overload implementations
- Dominant language
- Python
- Stars
- 202
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
simple scenario:
```py
@overload
def f(a: str) -> int: ...
@overload
def f(a: int) -> str: ...
def f(a):
return a
```
more realistic scenario:
```py
from typing import overload
@overload
def f(a: int) -> int: ...
@overload
def f(*, b: str) -> str: ...
def f(a: int | None=None, b: str=""):
if a:
return a + 1
return b
```
So this will not show the error of `f(0) # ""`
So the solution is to analyze the function for each overload, merging the overload and the defaults from the impl:
```py
def f(a: int | None=None, b: str="") -> int:
if a:
return a + 1
return b # error: expected "int", found "str"
# AND
def f(a: None=None, b: str="") -> str:
if a: # error: condition is always false
return a + 1
return b
```
This way we can collect the errors and work properly.
only problem is the "always true" errors we will run into, maybe we can inject a fake type into the parameters or something.
Contributor guide
Research direction
No source file or test entry point is named. Start by tracing how basedmypy processes @overload declarations and their implementation, then compare that path with return-type checking and constant-condition diagnostics. Done means each overload is checked against the implementation with merged defaults, while the resulting errors avoid misleading always-true or always-false reports.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100