Skip to content

Commit 8843129

Browse files
emmatypingJukkaL
authored andcommitted
Fix crash in PEP 561 module resoltion (#6000)
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.
1 parent 971e3a9 commit 8843129

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

mypy/modulefinder.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,14 @@ def _find_module(self, id: str) -> Optional[str]:
156156
# package if installed.
157157
if fscache.read(stub_typed_file).decode().strip() == 'partial':
158158
runtime_path = os.path.join(pkg_dir, dir_chain)
159-
third_party_inline_dirs.append((runtime_path, True))
160-
# if the package is partial, we don't verify the module, as
161-
# the partial stub package may not have a __init__.pyi
162-
third_party_stubs_dirs.append((path, False))
159+
third_party_inline_dirs.append((runtime_path, True))
160+
# if the package is partial, we don't verify the module, as
161+
# the partial stub package may not have a __init__.pyi
162+
third_party_stubs_dirs.append((path, False))
163+
else:
164+
# handle the edge case where people put a py.typed file
165+
# in a stub package, but it isn't partial
166+
third_party_stubs_dirs.append((path, True))
163167
else:
164168
third_party_stubs_dirs.append((path, True))
165169
non_stub_match = self._find_module_non_stub_helper(components, pkg_dir)

0 commit comments

Comments
 (0)