False positive for function that takes a `Callable` as a parameter and returns a `Tuple` of `Union`
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 42/100
Direzione di ricerca
Inizia eseguendo lo snippet Python fornito con mypy 0.812 e conferma l’errore nella chiamata di unpacking. Traccia l’inferenza delle variabili di tipo per Callable, Tuple e Union; il lavoro è completato quando il riproduttore supera il controllo dei tipi senza il falso positivo segnalato e la copertura di regressione protegge questo comportamento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug Report
The following code
from typing import (
Callable,
TypeVar,
Union,
Tuple,
)
T = TypeVar("T")
def test(pred: Callable[[T], bool]) -> Tuple[Union[T, int]]:
return (1,)
def main(pred: Callable[[T], bool]) -> None:
(val,) = test(pred) # the error appears here
def f(x: int) -> bool:
return x > 1
main(f)
triggers the mypy error
Argument 1 to "test" has incompatible type "Callable[[T], bool]"; expected "Callable[[Union[T, int]], bool]"
at the line that I marked with a comment. I believe this is a bug as this correction makes no sense to me (of couse, I could be wrong).
I'm aware that this code is meaningless, but it's the simplest sample I was able to produce that causes the error.
From the tests that I've done it seems to depend both on the type variable being used and on the function test returning a Tuple[Union[...]]. So if I replace T with a regular type of if I return either Union[T, int] or Tuple[int] instead of Tuple[Union[T, int]] the error goes away. It also disappears by not upacking the the result of test(pred).
To Reproduce
Take the code above and check it with mypy. That's it.
Expected Behavior
No error triggered.
Actual Behavior
Mypy detects the error reported above.
Your Environment
- Mypy version used: 0.812
- Mypy command-line flags: --ignore-missing-imports --follow-imports=silent --show-column-numbers
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.9.2
- Operating system and version: Linux x64
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Merge medio
- 1g 18h
- PR unite (30g)
- 54
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.
Altre issue di python/mypy
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
bug topic-configuration topic-error-reporting
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Issue simili
-
area/auth bug comp/agent P3 platform/discord type/security
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
NousResearch/hermes-agent#117848 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
bancolombia/sentinel#23 ·
-
test md ApertaCI
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100