Having a `packages` property in pyproject.toml makes mypy no longer check types in imports after installing the package with Poetry
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied pyproject.toml and the reproducer-main.py and some_module/reproducer-import.py files. Install with Poetry, then run poetry run mypy reproducer-main.py and compare behavior with and without the packages property. Done means mypy reports the annotated assignment error in reproducer-import.py when packages is present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100