Skip to content

Commit

Permalink
Fix crash in PEP 561 module resoltion (#6000)
Browse files Browse the repository at this point in the history
If there was a py.typed file in a stub-only package, and it didn't
contain "partial", there would be an unbound local error. To fix this,
we treat it as a normal stub-only package instead.
  • Loading branch information
emmatyping authored and JukkaL committed Dec 4, 2018
1 parent 971e3a9 commit 8843129
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions mypy/modulefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,14 @@ def _find_module(self, id: str) -> Optional[str]:
# package if installed.
if fscache.read(stub_typed_file).decode().strip() == 'partial':
runtime_path = os.path.join(pkg_dir, dir_chain)
third_party_inline_dirs.append((runtime_path, True))
# if the package is partial, we don't verify the module, as
# the partial stub package may not have a __init__.pyi
third_party_stubs_dirs.append((path, False))
third_party_inline_dirs.append((runtime_path, True))
# if the package is partial, we don't verify the module, as
# the partial stub package may not have a __init__.pyi
third_party_stubs_dirs.append((path, False))
else:
# handle the edge case where people put a py.typed file
# in a stub package, but it isn't partial
third_party_stubs_dirs.append((path, True))
else:
third_party_stubs_dirs.append((path, True))
non_stub_match = self._find_module_non_stub_helper(components, pkg_dir)
Expand Down

0 comments on commit 8843129

Please sign in to comment.