Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Can't find package" error when package is installed but missing a py.typed file #17048

Open
gmc444-b opened this issue Mar 19, 2024 · 0 comments
Labels
bug mypy got something wrong

Comments

@gmc444-b
Copy link
Contributor

gmc444-b commented Mar 19, 2024

Bug Report

A while back I opened #16634 but didn't provide enough details on how to reproduce the problem. Here I'm providing a reproducer.

When a package is installed without a py.typed file, installed into a virtual env, and then I run mypy -p packagename I get the error Can't find package packagename when a more appropriate error message should be provided.

To Reproduce

The following files make up the reproducer:

├── pyproject.toml
├── run-reproducer.sh
└── src
    └── reproducer
        └── __init__.py

The content of each file

#---- pyproject.toml

[build-system]
requires = ["setuptools"]
module_dir = "src"

[project]
name = "reproducer"
version = "0.1"

[project.scripts]
reproducer = "reproducer.__init__:main"

[tool.setuptools.package-data]
"*" = ["py.typed",]

#-------- src/reproducer/__init__.py

def main(args: list[str] | None=None) -> None:
    print("Hello from the reproducer")

#------- run-reproducer.sh

#!/usr/bin/env bash

python3.12 -m venv .venv
.venv/bin/pip install . mypy
.venv/bin/reproducer   # This works
.venv/bin/mypy -p reproducer --strict   # This fails to find the reproducer

Expected Behavior

Under other circumstances, users can get an error message saying that type information is missing from the given package. That would be the preferred error message for this use-case.

Actual Behavior

Set up the files as described above, run the run-reproducer.sh script to initialize a virtual env with the reproducer package and mypy installed, and invoke mypy. The output I get is Can't find package 'reproducer'

Your Environment

Python 3.12 on Ubuntu 22.04, but I'm also able to reproduce this on Red Hat systems.

  • Mypy version used: 1.0.9
  • Mypy command-line flags: -p reproducer --strict (but same failure without --strict)
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.12
@gmc444-b gmc444-b added the bug mypy got something wrong label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant