Skip to content

Using namespace package, editable mode installation and pyproject.toml makes mypy not find the package #15439

Closed as not planned
@mikolajz

Description

@mikolajz

Bug Report
When using a namespace package, editable mode installation and pyproject.toml makes mypy report "Can't find package". Without pyproject.toml the same commands work (likely because pyproject.toml triggers a different path in PIP).

To Reproduce

mkvirtualenv types-test
pip install pip==23.1.2 setuptools==67.7.2 wheel==0.40.0
pip install mypy==1.3.0
mkdir -p src/mypy_problem_test/foo1331

cat >src/mypy_problem_test/foo1331/__init__.py <<__EOF__
i: int = "abc"
__EOF__

touch src/mypy_problem_test/foo1331/py.typed

cat >setup.py <<__EOF__
from distutils.core import setup

setup(
    name='TestMypyProblem',
    version='0.1.0',
    url='https://github.com/mypackage.git',
    author='Author Name',
    author_email='author@gmail.com',
    description='Test for mypy problem',
    packages=['mypy_problem_test.foo1331'],
    package_dir={'': 'src'},
    install_requires=[],
    package_data={"mypy_problem_test.foo1331": ["py.typed"]},
    namespace_packages=['mypy_problem_test']
)
__EOF__

touch pyproject.toml
mypy -p mypy_problem_test.foo1331

Expected Behavior
Mypy reports Can't find package 'mypy_problem_test.foo1331'

Actual Behavior

Finding the type error (src/mypy_problem_test/foo1331/__init__.py:1: error: Incompatible types in assignment (expression has type "str", variable has type "int"))

Note: without the pyproject.toml file the result is exactly this.

Your Environment

  • Mypy version used: 1.3.0
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.10.6

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