From 34a919315450b88c2e21f76532e6f2c4f85ac40f Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sat, 27 Dec 2025 14:13:03 -0800 Subject: [PATCH 1/2] Improve error message for invalid Python package Resolves #17108 --- mypy/find_sources.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mypy/find_sources.py b/mypy/find_sources.py index ececbf9c1cb8..e1edebe90985 100644 --- a/mypy/find_sources.py +++ b/mypy/find_sources.py @@ -195,7 +195,10 @@ def _crawl_up_helper(self, dir: str) -> tuple[str, str] | None: if not name.isidentifier(): # in most cases the directory name is invalid, we'll just stop crawling upwards # but if there's an __init__.py in the directory, something is messed up - raise InvalidSourceList(f"{name} is not a valid Python package name") + raise InvalidSourceList( + f"{name} contains {os.path.basename(init_file)} " + "but is not a valid Python package name" + ) # we're definitely a package, so we always return a non-None value mod_prefix, base_dir = self.crawl_up_dir(parent) return module_join(mod_prefix, name), base_dir From cab0c785f9b4e7d8f2cf70d76a4fe37e6538cf35 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sat, 27 Dec 2025 14:32:12 -0800 Subject: [PATCH 2/2] . --- test-data/unit/cmdline.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-data/unit/cmdline.test b/test-data/unit/cmdline.test index 85d9fc920d19..64de97f0d686 100644 --- a/test-data/unit/cmdline.test +++ b/test-data/unit/cmdline.test @@ -106,7 +106,7 @@ dir/a.py:1: error: Name "undef" is not defined [file dir/sub.pkg/a.py] undef [out] -sub.pkg is not a valid Python package name +sub.pkg contains __init__.py but is not a valid Python package name == Return code: 2 [case testBadFileEncoding]