Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mypy/find_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def create_source_list(
finder = SourceFinder(fscache, options)

sources = []
empty_dirs = []
for path in paths:
path = os.path.normpath(path)
if path.endswith(PY_EXTENSIONS):
Expand All @@ -47,11 +48,13 @@ def create_source_list(
elif fscache.isdir(path):
sub_sources = finder.find_sources_in_dir(path)
if not sub_sources and not allow_empty_dir:
raise InvalidSourceList(f"There are no .py[i] files in directory '{path}'")
empty_dirs.append(path)
sources.extend(sub_sources)
else:
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.

return sources


Expand Down
8 changes: 8 additions & 0 deletions mypy/test/test_find_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ def test_find_sources_in_dir_namespace_multi_dir(self) -> None:
finder = SourceFinder(FakeFSCache({"/a/pkg/a.py", "/b/pkg/b.py"}), options)
assert find_sources_in_dir(finder, "/") == [("pkg.a", "/a"), ("pkg.b", "/b")]

def test_find_sources_with_empty_directory(self) -> None:
options = Options()
fscache = FakeFSCache({"/empty/README", "/src/a.py"})

assert find_sources(["/empty", "/src"], options, fscache) == [("a", "/src")]
with pytest.raises(InvalidSourceList, match=r"directory '.*[\\/]empty'"):
find_sources(["/empty"], options, fscache)

def test_find_sources_exclude(self) -> None:
options = Options()
options.namespace_packages = True
Expand Down
Loading