Using mypy via pre-commit
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
pre-commit is useful; many mypy users use mypy via pre-commit. This issue exists so I can link to it when users run into common gotchas. Please do not discuss pre-commit related feature requests here, open a new issue.
pre-commit runs mypy in an isolated environment
pre-commit wants checks to run in isolated environments. mypy wants to know as much about your program as it can, including everything about everything you import. These are in conflict.
The pre-commit mypy mirror thing automatically (and to most users, surprisingly) passes --ignore-missing-imports, which means that most types originating from third party dependencies will become Any: https://github.com/pre-commit/mirrors-mypy/blob/33f4a30be4e66513c51a857712fc732e1a9ddd78/.pre-commit-hooks.yaml#L7
In my opinion, this is really bad: it will silently make type checking far less effective. It also means you'll likely get different results when running mypy directly.
Two possible pre-commit fixes in your pre-commit config:
- Use
language: system(and maybe a helper script) to run something from outside a pre-commit environment - Repeat your list of dependencies (and stub dependencies) in
additional_dependencies
pre-commit passes only diffed files
This is sort of the core idea of pre-commit and for most pre-commit checks, this is great. But mypy really wants to do whole program analysis, and will try to follow all imports, so pre-commit is not actually saving you any work. In fact, if it is saving you work, it's probably undesirable and some bug in your mypy setup. Anyway, this is another source of potential differences between running mypy directly, e.g. there are undesirable interactions with --exclude: mypy assumes that if you pass a file in the command, you want it to be checked.
Recommended pre-commit fix:
In your pre-commit config, use pass_filenames: false
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
Non è stato indicato alcun file o test del repository mypy. Inizia esaminando il comportamento documentato di pre-commit e il file .pre-commit-hooks.yaml collegato, quindi chiedi indicazioni ai maintainer sulla posizione e sull'ambito previsti per la documentazione prima di apportare modifiche.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Attiva
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 35/100