python / python/mypy

exclude does not work when file contains invalid syntax?

Aperta
#14,670 1 commento 5 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

Bug Report

I'm having an issue with exclude. Basically, I exclude my tests/fixtures folder because it contains code with syntax that is only supported by Python 3.8, 3.9, etc, while my project supports Python 3.7. So the files in tests/fixtures contain invalid syntax on Python 3.7.

When I run mypy on Python 3.7, it errors with this:

tests/fixtures/validation_38.py:1: error: invalid syntax [syntax]
Found 1 error in 1 file (errors prevented further checking)

I exclude the folder with exclude = tests/fixtures in mypy.ini.
I tried excluding the file name directly, for example with exclude = validation_38\.py but it still fails the same way.

To Reproduce

# tests/fixtures/validation_38.py
def full(ctx, a: int, /, b: int, *c: int, d: int, e: int = 0, **f: int):
    pass

Checking only the parent folder, I'm able to exclude it:

% python3.7 -m mypy --exclude validation_38.py --ignore-missing-imports tests/fixtures/
Success: no issues found in 8 source files

Any other way fails:

% python3.7 -m mypy --exclude validation_38.py --ignore-missing-imports tests          
tests/fixtures/validation_38.py:1: error: invalid syntax  [syntax]
Found 1 error in 1 file (errors prevented further checking)
% python3.7 -m mypy --exclude fixtures/validation_38.py --ignore-missing-imports tests
tests/fixtures/validation_38.py:1: error: invalid syntax  [syntax]
Found 1 error in 1 file (errors prevented further checking)
% python3.7 -m mypy --exclude '.*/validation_38\.py' --ignore-missing-imports tests
tests/fixtures/validation_38.py:1: error: invalid syntax  [syntax]
Found 1 error in 1 file (errors prevented further checking)
% python3.7 -m mypy --exclude tests/fixtures --ignore-missing-imports tests
tests/fixtures/validation_38.py:4: error: invalid syntax  [syntax]
Found 1 error in 1 file (errors prevented further checking)
% python3.7 -m mypy --exclude fixtures --ignore-missing-imports tests 
tests/fixtures/validation_38.py:4: error: invalid syntax  [syntax]
Found 1 error in 1 file (errors prevented further checking)

Expected Behavior

Invalid syntax errors should be ignored if the file in question is excluded.
It seemed to work previously (before 1.0.0?).

Actual Behavior

An excluded file with invalid syntax makes mypy terminate with an error.

Your Environment

  • Python version used: 3.7
  • Mypy version used: 1.0.0
  • Mypy command-line flags: see above
  • Mypy configuration options from mypy.ini (not used in the examples above):
[mypy]
ignore_missing_imports = true
exclude = tests/fixtures
warn_unused_ignores = true
show_error_codes = true

Possibly related to https://github.com/python/mypy/issues/9981 and https://github.com/python/mypy/issues/6897.

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 i comandi segnalati con Python 3.7 e mypy 1.0.0, quindi traccia il modo in cui la CLI applica --exclude e l'esclusione di mypy.ini durante la ricerca dei file in tests. Il lavoro è completato quando i file esclusi che contengono sintassi non supportata non producono errori di sintassi, i file non esclusi vengono comunque controllati e la regressione pertinente è coperta da un test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 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.