Skip to content

Commit 739f067

Browse files
author
hauntsaninja
committed
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)
1 parent dfaf104 commit 739f067

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mypy/find_sources.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ def crawl_up(self, path: str) -> Tuple[str, str]:
131131
parent, filename = os.path.split(path)
132132

133133
module_name = strip_py(filename) or filename
134-
if not module_name.isidentifier():
135-
return module_name, parent
136134

137135
parent_module, base_dir = self.crawl_up_dir(parent)
138136
if module_name == "__init__":
139137
return parent_module, base_dir
140138

139+
# Note that module_name might not actually be a valid identifier, but that's okay
140+
# Ignoring this possibility sidesteps some search path confusion
141141
module = module_join(parent_module, module_name)
142142
return module, base_dir
143143

0 commit comments

Comments
 (0)