python / python/mypy

local stubs folder makes mypy think an unrelated `module.__init__` duplicates `module`

Open
#18,775 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

Having a local stubs folder makes mypy think an unrelated module.__init__ duplicates module.

Deleting the __init__.pyi in the local stubs solves the issue, but will cause many more issues where mypy thinks the package can't be imported.

This happens with or without explicit_package_bases.

To Reproduce

MRE: reproduction.zip

Expected Behavior

No error or some way to work around this issue

Actual Behavior

my_package\_dynamic\__init__.py: error: Source file found twice under different module names: "my_package._dynamic" and "my_package._dynamic.__init__"
my_package\_dynamic\__init__.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
my_package\_dynamic\__init__.py: note: Common resolutions include: a) adding `__init__.py` somewhere, b) using `--explicit-package-bases` or adjusting MYPYPATH
Found 1 error in 1 file (errors prevented further checking)

Your Environment

  • Mypy version used: mypy 1.15.0 (compiled: yes)
  • Mypy command-line flags: python3.13 -m mypy .
  • Mypy configuration options from mypy.ini (and other config files): (see MRE)
  • Python version used: Python 3.13.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by unpacking reproduction.zip and running python3.13 -m mypy . with the included configuration and local stubs. Trace the module-path handling that reports both my_package._dynamic and my_package._dynamic.__init__; done means the duplicate-module error is avoided without making the stubs package unimportable.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.