python / python/mypy

Cannot suppress python_version-related errors in third-party code

Offen
#9,972 12 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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)

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die setup.cfg-Konfiguration mit python_version = 3.5, der importlib_metadata-Abhängigkeit, test.py und mypy test.py zu reproduzieren. Verfolge, wie mypy mit versionsbezogenen Syntaxfehlern aus importierten Abhängigkeiten umgeht; als abgeschlossen gilt die Aufgabe, wenn test.py weiterhin Python 3.5 erzwingt, während die versionsbezogenen Fehler der Abhängigkeit durch ignore_errors unterdrückt werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.