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

Method clone_for_module

mypy/options.py:593–634  ·  view source on GitHub ↗

Create an Options object that incorporates per-module options. NOTE: Once this method is called all Options objects should be considered read-only, else the caching might be incorrect.

(self, module: str)

Source from the content-addressed store, hash-verified

591 self._unused_configs.update(structured_keys)
592
593 def clone_for_module(self, module: str) -> Options:
594 """Create an Options object that incorporates per-module options.
595
596 NOTE: Once this method is called all Options objects should be
597 considered read-only, else the caching might be incorrect.
598 """
599 if self._per_module_cache is None:
600 self.build_per_module_cache()
601 assert self._per_module_cache is not None
602
603 # If the module just directly has a config entry, use it.
604 if module in self._per_module_cache:
605 self._unused_configs.discard(module)
606 return self._per_module_cache[module]
607
608 # If not, search for glob paths at all the parents. So if we are looking for
609 # options for foo.bar.baz, we search foo.bar.baz.*, foo.bar.*, foo.*,
610 # in that order, looking for an entry.
611 # This is technically quadratic in the length of the path, but module paths
612 # don't actually get all that long.
613 options = self
614 path = module.split(".")
615 for i in range(len(path), 0, -1):
616 key = ".".join(path[:i] + ["*"])
617 if key in self._per_module_cache:
618 self._unused_configs.discard(key)
619 options = self._per_module_cache[key]
620 break
621
622 # OK and *now* we need to look for unstructured glob matches.
623 # We only do this for concrete modules, not structured wildcards.
624 if not module.endswith(".*"):
625 for key, pattern in self._glob_options:
626 if pattern.match(module):
627 self._unused_configs.discard(key)
628 options = options.apply_changes(self.per_module_options[key])
629
630 # We could update the cache to directly point to modules once
631 # they have been looked up, but in testing this made things
632 # slower and not faster, so we don't bother.
633
634 return options
635
636 def get_unused_configs(self) -> set[str]:
637 return self._unused_configs.copy()

Callers 9

options_snapshotFunction · 0.80
new_stateMethod · 0.80
verify_dependenciesMethod · 0.80
exist_added_packagesFunction · 0.80
load_graphFunction · 0.80
load_statesFunction · 0.80

Calls 8

rangeClass · 0.85
lenFunction · 0.85
discardMethod · 0.80
splitMethod · 0.80
apply_changesMethod · 0.80
joinMethod · 0.45
endswithMethod · 0.45

Tested by

no test coverage detected