Skip to content

Fix discovery beside same-named namespace directories - #22168

Open
nightcityblade wants to merge 1 commit into
python:masterfrom
nightcityblade:fix/issue-22160
Open

nightcityblade wants to merge 1 commit into
python:masterfrom
nightcityblade:fix/issue-22160

Conversation

@nightcityblade

Copy link
Copy Markdown

Fixes #22160.

Directory discovery currently reserves every populated directory name before considering same-named Python files. That incorrectly skips x.py when a namespace directory such as x/y.py is also present.

This change reserves a directory name only when the directory is a regular package with an __init__.py[i]. Regression tests cover both namespace-directory discovery and the existing regular-package precedence.

Supersedes #22166, which GitHub auto-closed after the head branch history was repaired.

Testing:

  • TMPDIR=/tmp/mypytest .venv/bin/python -m pytest -n0 mypy/test/test_find_sources.py (11 passed)
  • .venv/bin/python -m mypy --config-file mypy_self_check.ini mypy/find_sources.py mypy/test/test_find_sources.py
  • Black 26.1.0, Ruff, and codespell checks on the changed files

Development note: this focused change was prepared with AI-assisted tooling and manually reviewed and validated against the reported behavior.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

scipy-stubs (https://github.com/scipy/scipy-stubs)
- tests/misc/test_submodules_empty.pyi:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File x.py is skiped if directory x exists

1 participant