stubtest false positive: default (list,) incompatible with tuple[type[list[_T]]]
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo il report con Python 3.11.3 usando python -m mypy.stubtest lib e confrontando le firme in lib.py e lib.pyi. Traccia il modo in cui stubtest valuta il valore predefinito a runtime (list,) rispetto a tuple[type[list[_T]]]; il lavoro è completato quando la discrepanza foo1 segnalata viene accettata, mentre i casi foo2 e foo3 esistenti rimangono coperti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- testing-qa, tooling
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100