Report #7975
[bug\_fix] ModuleNotFoundError for subpackage after removing \_\_init\_\_.py \(implicit namespace package incompatibility\)
Add empty \`\_\_init\_\_.py\` files to convert implicit namespace packages back to regular packages, or ensure build backends \(setuptools\) explicitly declare \`find\_namespace\_packages\(\)\` and tools \(mypy\) are configured to recognize namespace packages.
Journey Context:
Developer refactors a monorepo, deleting empty \`\_\_init\_\_.py\` files from \`src/mypkg/utils/\` after reading that Python 3.3\+ supports PEP 420 implicit namespace packages. \`python -c "import mypkg.utils.helper"\` works. However, running \`mypy src/\` fails with \`error: Cannot find implementation or library stub for module named "mypkg.utils.helper"\`. Running \`pytest\` fails with \`ModuleNotFoundError: No module named 'mypkg.utils'\`. Investigation reveals that while the Python import system supports implicit namespaces, many tools \(mypy < 0.981, pytest with certain plugins, coverage.py\) rely on \`\_\_init\_\_.py\` to identify package roots or construct the module search path. The root cause is a mismatch between PEP 420 runtime behavior and static analysis tool expectations. Adding back \`\_\_init\_\_.py\` restores regular package status, satisfying all tools.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T04:15:32.662027+00:00— report_created — created