Skip to content

Allow valid targets alongside empty directories - #22177

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

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

Conversation

@nightcityblade

Copy link
Copy Markdown

Fixes #22173

create_source_list now defers the existing empty-directory error until all explicit targets have been scanned. This lets mypy check valid targets alongside an empty directory while preserving the fatal error when no sources are found.

A regression test covers both the mixed-target and all-empty cases.

Validation:

  • TMPDIR=/tmp .venv/bin/python -m pytest -n0 mypy/test/test_find_sources.py -q (10 passed)
  • .venv/bin/python runtests.py lint (passed)
  • .venv/bin/python runtests.py self (346 source files checked successfully)
  • .venv/bin/python -m mypy .github . against the issue reproduction (success; 1 source file)

AI assistance: Codex helped draft the focused change and test; I reviewed the diff and ran all validation locally.

@github-actions

This comment has been minimized.

@nightcityblade

nightcityblade commented Oct 11, 2026 •

Copy link
Copy Markdown
Author

Fixed the Windows-only test expectation in 7d71289 by accepting both POSIX and drive-prefixed Windows separators. I also folded pre-commit.ci’s import-spacing auto-fix into the authored commit, preserving single-commit history. The focused 10-test suite passed before the formatting-only bot change; the final tree passes Ruff, ruff format, py_compile, and git diff --check. CI is rerunning.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@Zocker1999NET Zocker1999NET left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm & should fix my issue. thanks for implementing that so fast ❤️

now only a maintainer decision is required for this change

Comment thread mypy/find_sources.py
mod = os.path.basename(path) if options.scripts_are_modules else None
sources.append(BuildSource(path, mod, None))
if not sources and empty_dirs:
raise InvalidSourceList(f"There are no .py[i] files in directory '{empty_dirs[0]}'")

@Zocker1999NET Zocker1999NET Oct 11, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because multiple dirs can be supplied & the error now only occurs when all dirs are "empty", I would just list all dirs in the error:

Suggested change
raise InvalidSourceList(f"There are no .py[i] files in directory '{empty_dirs[0]}'")
empty_dirs_str = ", ".join(map(repr, empty_dirs))
raise InvalidSourceList(f"There are no .py[i] files in directories: {empty_dirs_str}")

(and then also improve the escaping of the path strings, some Linux users have e.g. ' in their paths xD)

EDIT: This suggestion requires a small adaption on the test, because the message no longer matches because I used the plural directories.

@nightcityblade

Copy link
Copy Markdown
Author

Thanks for confirming the fix works for your issue and for the approval!

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.

empty directory among multiple targets aborts whole check

2 participants