stubtest false positive: default (list,) incompatible with tuple[type[list[_T]]]
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Mypy stubtests report a false positive for a signature of tuple[type[list[_T]]] and a default value of (list,).
Removing either the wrapping tuple or the TypeVar is accepted.
To Reproduce
def foo1(x = (list,)): ...
def foo2(x = (list,)): ...
def foo3(x = list): ...
from typing import TypeVar
_T = TypeVar('_T')
def foo1(x: tuple[type[list[_T]]] = ...): ...
def foo2(x: tuple[type[list]] = ...): ...
def foo3(x: type[list[_T]] = ...): ...
Expected Behavior
Stubtests accept this
Actual Behavior
$ python -m mypy.stubtest lib
error: lib.foo1 is inconsistent, runtime parameter "x" has a default value of type tuple[Overload(def [_T] () -> builtins.list[_T`1], def [_T] (typing.Iterable[_T`1]) -> builtins.list[_T`1])], which is incompatible with stub parameter type tuple[type[builtins.list[_T`-1]]]
Stub: in file D:\Programming\Projects\Testing\lib.pyi:5
def [_T] (x: tuple[type[builtins.list[_T`-1]]] =) -> Any
Runtime: in file D:\Programming\Projects\Testing\lib.py:1
def (x=(<class 'list'>,))
Found 1 error (checked 1 module)
Your Environment
Command: python -m mypy.stubtest lib
Python Version: Python 3.11.3
Mypy Version: mypy 1.18.1 (compiled: yes)
From: https://github.com/python/typeshed/issues/14718#issuecomment-3290882846
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 report with Python 3.11.3 using python -m mypy.stubtest lib, comparing the signatures in lib.py and lib.pyi. Trace how stubtest evaluates the runtime default (list,) against tuple[type[list[_T]]]; done means the reported foo1 mismatch is accepted while the existing foo2 and foo3 cases remain covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100