Skip to content

Commit

Permalink
don't change base dir if module name is invalid
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
hauntsaninja committed Nov 22, 2020
1 parent dfaf104 commit 739f067
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mypy/find_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 739f067

Please sign in to comment.