From 739f06778111c31bfd4d0a8f37dafe6d342665af Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Sun, 22 Nov 2020 00:17:46 -0800 Subject: [PATCH] don't change base dir if module name is invalid mypy_primer points out two undesirable effects: 1) scripts causing search path confusion 2) scripts with the same names causing issues (e.g. migrations in zulip) --- mypy/find_sources.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mypy/find_sources.py b/mypy/find_sources.py index 995f97dcafe4..63744e8caee1 100644 --- a/mypy/find_sources.py +++ b/mypy/find_sources.py @@ -131,13 +131,13 @@ def crawl_up(self, path: str) -> Tuple[str, str]: parent, filename = os.path.split(path) module_name = strip_py(filename) or filename - if not module_name.isidentifier(): - return module_name, parent parent_module, base_dir = self.crawl_up_dir(parent) if module_name == "__init__": return parent_module, base_dir + # Note that module_name might not actually be a valid identifier, but that's okay + # Ignoring this possibility sidesteps some search path confusion module = module_join(parent_module, module_name) return module, base_dir