Skip to content

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

@gmc444-b

Description

@gmc444-b

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions