Error with mixing str and pathlib.Path in command line arguments list
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 raises error if list of command line arguments (passing to subprocess.call) contains items of different types (for example, str and pathlib.Path). It can be fixed by adding type hint to variable, but it's too annoying.
To Reproduce
import pathlib
import subprocess
cmd = [pathlib.Path('bash'), '-c', 'echo Hello']
subprocess.call(cmd)
Expected Behavior
mypy should not raise any error.
Actual Behavior
main.py:5: error: Argument 1 to "check_call" has incompatible type "List[object]"; expected "Union[Union[str, bytes, PathLike[str], PathLike[bytes]], Sequence[Union[str, bytes, PathLike[str], PathLike[bytes]]]]"
Found 1 error in 1 file (checked 1 source file)
Why can't mypy recognize cmd type as List[Union[pathlib.Path, str]], not List[object]?
Environment
- Mypy version used: 0.961
- Python version used: 3.10
- Operating system: Linux
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 con il riproduttore Python fornito e con il tipaggio di subprocess.call, quindi traccia il modo in cui mypy deduce il tipo di una lista mista contenente pathlib.Path e str. Conferma la modifica con un test di regressione che utilizzi la lista di argomenti della riga di comando mostrata e verifica che mypy non segnali alcun errore, mentre i controlli esistenti sugli argomenti di subprocess rimangano intatti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100