Having a `packages` property in pyproject.toml makes mypy no longer check types in imports after installing the package with Poetry
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con il file pyproject.toml fornito e con i file reproducer-main.py e some_module/reproducer-import.py. Installa con Poetry, poi esegui poetry run mypy reproducer-main.py e confronta il comportamento con e senza la proprietà packages. Il risultato è raggiunto quando mypy segnala l'errore di assegnazione annotata in reproducer-import.py quando packages è presente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100