From 60a66e27b91336f6802b3b03d830e0d505fe6ac0 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Mon, 3 Dec 2018 16:40:17 -0800 Subject: [PATCH] Fix crash in PEP 561 module resoltion 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. --- mypy/modulefinder.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mypy/modulefinder.py b/mypy/modulefinder.py index 7d512fa7846d..252ec3bcb096 100644 --- a/mypy/modulefinder.py +++ b/mypy/modulefinder.py @@ -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)