bug: strict = true is incompatible with per-module configuration
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das Problem mit den gezeigten mypy.ini- und pyproject.toml-Konfigurationen und verfolge anschließend, wie strict- und Per-Module-Optionen bei der Ausführung von mypy . verarbeitet werden. Als erledigt gilt die Aufgabe, wenn strict auf my_module.* angewendet wird, während tests.* in beiden unterstützten Konfigurationsformaten nicht typisierte Definitionen akzeptiert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100