Skip to content

Commit

Permalink
Properly handle glob options and simplify detection
Browse files Browse the repository at this point in the history
  • Loading branch information
DeinAlptraum committed Nov 23, 2024
1 parent f9cf0ac commit ccd9cf7
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions mypy/modulefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,11 @@ def _typeshed_has_version(self, module: str) -> bool:
return version >= min_version and (max_version is None or version <= max_version)

def _find_module_non_stub_helper(
self, components: list[str], pkg_dir: str
self, id: str, pkg_dir: str
) -> OnePackageDir | ModuleNotFoundReason:
plausible_match = False
dir_path = pkg_dir
components = id.split(".")
for index, component in enumerate(components):
dir_path = os_path_join(dir_path, component)
if self.fscache.isfile(os_path_join(dir_path, "py.typed")):
Expand All @@ -351,17 +352,9 @@ def _find_module_non_stub_helper(
break
if plausible_match:
if self.options:
enable_installed_packages = self.options.enable_installed_packages
try:
enable_installed_packages = cast(
bool,
self.options.per_module_options[components[0]][
"enable_installed_packages"
],
)
except KeyError:
pass
if enable_installed_packages:
module_specific_options = self.options.clone_for_module(id)
if module_specific_options.enable_installed_packages:
# print("Returning ", id)
return os.path.join(pkg_dir, *components[:-1]), False
return ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS
else:
Expand Down Expand Up @@ -476,7 +469,7 @@ def _find_module(self, id: str, use_typeshed: bool) -> ModuleSearchResult:
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)
non_stub_match = self._find_module_non_stub_helper(id, pkg_dir)
if isinstance(non_stub_match, ModuleNotFoundReason):
if non_stub_match is ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS:
found_possible_third_party_missing_type_hints = True
Expand Down

0 comments on commit ccd9cf7

Please sign in to comment.