MCPcopy Index your code
hub / github.com/python/mypy / find_relative_leaf_module

Function find_relative_leaf_module

mypy/server/update.py:686–710  ·  view source on GitHub ↗

Find a module in a list that directly imports no other module in the list. If no such module exists, return the lexicographically first module from the list. Always return one of the items in the modules list. NOTE: If both 'abc' and 'typing' have changed, an effect of the above rule i

(modules: list[tuple[str, str]], graph: Graph)

Source from the content-addressed store, hash-verified

684
685
686def find_relative_leaf_module(modules: list[tuple[str, str]], graph: Graph) -> tuple[str, str]:
687 """Find a module in a list that directly imports no other module in the list.
688
689 If no such module exists, return the lexicographically first module from the list.
690 Always return one of the items in the modules list.
691
692 NOTE: If both 'abc' and 'typing' have changed, an effect of the above rule is that
693 we prefer 'abc', even if both are in the same SCC. This works around a false
694 positive in 'typing', at least in tests.
695
696 Args:
697 modules: List of (module, path) tuples (non-empty)
698 graph: Program import graph that contains all modules in the module list
699 """
700 assert modules
701 # Sort for repeatable results.
702 modules = sorted(modules)
703 module_set = {module for module, _ in modules}
704 for module, path in modules:
705 state = graph[module]
706 if len(set(state.dependencies) & module_set) == 0:
707 # Found it!
708 return module, path
709 # Could not find any. Just return the first module (by lexicographic order).
710 return modules[0]
711
712
713def delete_module(module_id: str, path: str, graph: Graph, manager: BuildManager) -> None:

Callers 1

update_module_isolatedFunction · 0.85

Calls 3

sortedFunction · 0.85
lenFunction · 0.85
setClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…