bug: strict = true is incompatible with per-module configuration

Aperta
#11,401 11 commenti 30 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
tooling

Direzione di ricerca

Riproduci il problema con le configurazioni mypy.ini e pyproject.toml mostrate, quindi traccia il modo in cui vengono elaborate le opzioni strict e per modulo quando si esegue mypy . Il lavoro è completato quando strict si applica a my_module.* mentre tests.* accetta definizioni senza annotazioni di tipo in entrambi i formati di configurazione supportati.

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

Descrizione

bug topic-configuration

To Reproduce

Create the following file structure:

my_module/__init__.py
tests/__init__.py
mypy.ini

Both my_module/__init__.py and tests/__init__.py contain:

def untyped():
    ...

Which should trigger an error when run with strict but otherwise pass.

In mypy.ini:

[mypy]
strict = true
[mypy-tests.*]
strict = false

That is, I want strict mode in my source code but not my tests.

Then I run this using mypy .

Expected Behavior

I expect to get an error for my source code but not my tests:

my_module/__init__.py:1: error: Function is missing a return type annotation
my_module/__init__.py:1: note: Use "-> None" if function does not return a value

Actual Behavior

I get an error for both my source code and tests.
It seems like strict = False in the per module section is ignored.

tests/__init__.py:1: error: Function is missing a return type annotation
tests/__init__.py:1: note: Use "-> None" if function does not return a value
my_module/__init__.py:1: error: Function is missing a return type annotation
my_module/__init__.py:1: note: Use "-> None" if function does not return a value

If I add an explicit allow_untyped_defs = True to the mypy-tests.* section:

[mypy]
strict = true
[mypy-tests.*]
strict = false
allow_untyped_defs = True

That seems to be processed fine (I now get no errors for my tests but still get errors for my source).
So I believe the config file is valid, mypy is picking up that the options only apply to tests.*.

I also tried flipping the enable/disable:

[mypy]
strict = false
[mypy-my_module.*]
strict = true

But I get the same result.

This also seems to be the case with pyproject.toml configs.

Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Merge medio
1g 18h
PR unite (30g)
54

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.

Altre issue di python/mypy

Tutte le issue di python/mypy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.