Bug Report
Given the runtime function:
def foo(x=0, ret=1):
return ret
stubtest is happy with these stubs:
from typing import TypeVar, overload
_T = TypeVar("_T")
@overload
def foo(x: int = 0) -> int: ...
@overload
def foo(x: int, ret: _T) -> _T: ...
but complains about these stubs (with a third overload added):
from typing import TypeVar, overload
_T = TypeVar("_T")
@overload
def foo(x: int = 0) -> int: ...
@overload
def foo(x: int, ret: _T) -> _T: ...
@overload
def foo(x: int = 0, *, ret: _T) -> _T: ... # added
with the error:
error: main.foo is inconsistent, runtime parameter "ret" has a default value of type Literal[1], which is incompatible with stub parameter type _T | _T. This is often caused by overloads failing to account for explicitly passing in the default value.
Stub: in file main.pyi:5
Overload(def (x: int =) -> int, def [_T] (x: int, ret: _T) -> _T, def [_T] (x: int =, *, ret: _T) -> _T)
Inferred signature: def (x: int = ..., ret: _T | _T = ...)
Runtime: in file main.py:1
def (x=0, ret=1)
Found 1 error (checked 1 module)
Your Environment
- Mypy version used: master,
mypy 2.2.0+dev.e15a6d58d
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini (and other config files): none
- Python version used: 3.13.13
Bug Report
Given the runtime function:
stubtest is happy with these stubs:
but complains about these stubs (with a third overload added):
with the error:
Your Environment
mypy 2.2.0+dev.e15a6d58dmypy.ini(and other config files): none