python / python/mypy

Cannot suppress python_version-related errors in third-party code

Aperta
#9,972 12 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug Report

If i have python_version = 3.5 set, it's not possible to tell mypy to ignore related syntax errors it finds in dependencies.

Use case: i have code which needs to support python 3.5, as well as newer versions. I run mypy against it under various versions of python, with python_version = 3.5 set so that i don't accidentally introduce something which is incompatible (like variable annotations) which might not get caught until later. This has worked fine until some of the dependencies have started using variable annotations.

To Reproduce

  1. Create a venv using python 3.6+.
  2. pip install mypy importlib-metadata # Using importlib-metadata as an example lib which uses variable annotations
  3. Create setup.cfg with:
[mypy]
python_version = 3.5

[mypy-importlib_metadata]
ignore_errors = True
  1. Create test.py with:
import importlib_metadata
  1. Run mypy test.py

Expected Behavior

mypy should enforce python_version = 3.5 for test.py, but it should ignore any version-related issues in importlib_metadata.

Actual Behavior

mypy fails with:

venv/lib/python3.8/site-packages/importlib_metadata/__init__.py:88: error: Variable annotation syntax is only supported in Python 3.6 and greater
Found 1 error in 1 file (errors prevented further checking)

mypy doesn't seem to treat this as a 'fatal' error, either, as setting pdb = True has no effect.

Your Environment

  • mypy 0.790 and 0.800
  • python 3.6.7, 3.6.12 and 3.8.5
  • Debian Stretch and Linux Mint 20.1 (Equivalent to Ubuntu 20.04)

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo la configurazione di setup.cfg con python_version = 3.5, la dipendenza importlib_metadata, test.py e mypy test.py. Traccia il modo in cui mypy gestisce gli errori di sintassi relativi alla versione provenienti dalle dipendenze importate; il lavoro è completato quando test.py continua a imporre Python 3.5 mentre gli errori relativi alla versione della dipendenza vengono soppressi da ignore_errors.

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
Specificata chiaramente
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.