MCPcopy
hub / github.com/python/mypy / find_module

Method find_module

mypy/modulefinder.py:309–337  ·  view source on GitHub ↗

Return the path of the module source file or why it wasn't found. If fast_path is True, prioritize performance over generating detailed error descriptions.

(self, id: str, *, fast_path: bool = False)

Source from the content-addressed store, hash-verified

307 return components.get(id, [])
308
309 def find_module(self, id: str, *, fast_path: bool = False) -> ModuleSearchResult:
310 """Return the path of the module source file or why it wasn't found.
311
312 If fast_path is True, prioritize performance over generating detailed
313 error descriptions.
314 """
315 if id not in self.results:
316 top_level = id.partition(".")[0]
317 use_typeshed = True
318 if id in self.stdlib_py_versions:
319 use_typeshed = self._typeshed_has_version(id)
320 elif top_level in self.stdlib_py_versions:
321 use_typeshed = self._typeshed_has_version(top_level)
322 result, should_cache = self._find_module(id, use_typeshed)
323 if should_cache:
324 if (
325 not (
326 fast_path or (self.options is not None and self.options.fast_module_lookup)
327 )
328 and result is ModuleNotFoundReason.NOT_FOUND
329 and self._can_find_module_in_parent_dir(id)
330 ):
331 self.results[id] = ModuleNotFoundReason.WRONG_WORKING_DIRECTORY
332 else:
333 self.results[id] = result
334 return self.results[id]
335 else:
336 return result
337 return self.results[id]
338
339 def _typeshed_has_version(self, module: str) -> bool:
340 if not self.options:

Callers 15

_find_moduleMethod · 0.95
build_stubsFunction · 0.95
find_added_suppressedMethod · 0.95
process_optionsFunction · 0.95
parse_moduleMethod · 0.95
__init__Method · 0.45
find_module_simpleFunction · 0.45
find_module_with_reasonFunction · 0.45

Calls 4

_typeshed_has_versionMethod · 0.95
_find_moduleMethod · 0.95
partitionMethod · 0.80