python / python/mypy

Having a `packages` property in pyproject.toml makes mypy no longer check types in imports after installing the package with Poetry

Offen
#16,755 1 Kommentar 0 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

I've been having the issue that Mypy suddenly no longer type checks the contents of my imports, even though they are in the same source tree. After bisecting the issue, I figured out that the cause was the addition of the packages line to my pyproject.toml file by a co-worker. This behaviour is strange to me, so it seems like a bug likely in mypy?

To Reproduce

pyproject.toml:

[tool.poetry]
name = "mypy-issue-reproducer"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"
packages = [
    { include = "**/*.py" },
]

[tool.poetry.dependencies]
python = "^3.10"

[tool.poetry.group.dev.dependencies]
mypy = "^1.8.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

reproducer-main.py:

from some_module.reproducer_import import main

main()

some_module/reproducer-import.py:

def main():
    # blatant violation
    variable: str = 1

README.md also needs to be created and can contain whatever.

Creating these files and installing the project with $ poetry install --with dev, then running $ poetry run mypy reproducer-main.py reproduces the issue (note how mypy does not complain about the blatant type violation in reproducer-import.py). Removing the packages property, then removing the virtualenv and repeating the install and Mypy steps now has Mypy actually report the aforementioned type violation.

If you just want a git repository to clone, here you go: https://github.com/Newbytee/mypy-bug-reproducer

Expected Behavior

Mypy type checks the main function in reproducer-import.py.

Actual Behavior

Mypy does not care that the main function in reproducer-import.py has a blatant type violation:

$ poetry run mypy reproducer-main.py 
Success: no issues found in 1 source file

Your Environment

  • Mypy version used: 1.8.0 (compiled: yes)
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: Python 3.10.12

This happens both in my Ubuntu 22.04 LTS container and also my CI using both the python:3.10 image and the python:3.11 image.

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 mit der bereitgestellten pyproject.toml sowie den Dateien reproducer-main.py und some_module/reproducer-import.py. Installiere mit Poetry und führe dann poetry run mypy reproducer-main.py aus; vergleiche das Verhalten mit und ohne die packages-Eigenschaft. Erledigt ist es, wenn mypy den Fehler bei der annotierten Zuweisung in reproducer-import.py meldet, sobald packages vorhanden ist.

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.