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

Function find_targets_recursive

mypy/server/update.py:900–959  ·  view source on GitHub ↗

Find names of all targets that need to reprocessed, given some triggers. Returns: A tuple containing a: * Dictionary from module id to a set of stale targets. * A set of module ids for unparsed modules with stale targets.

(
    manager: BuildManager,
    graph: Graph,
    triggers: set[str],
    deps: dict[str, set[str]],
    up_to_date_modules: set[str],
)

Source from the content-addressed store, hash-verified

898
899
900def find_targets_recursive(
901 manager: BuildManager,
902 graph: Graph,
903 triggers: set[str],
904 deps: dict[str, set[str]],
905 up_to_date_modules: set[str],
906) -> tuple[dict[str, set[FineGrainedDeferredNode]], set[str], set[TypeInfo]]:
907 """Find names of all targets that need to reprocessed, given some triggers.
908
909 Returns: A tuple containing a:
910 * Dictionary from module id to a set of stale targets.
911 * A set of module ids for unparsed modules with stale targets.
912 """
913 result: dict[str, set[FineGrainedDeferredNode]] = {}
914 worklist = triggers
915 processed: set[str] = set()
916 stale_protos: set[TypeInfo] = set()
917 unloaded_files: set[str] = set()
918
919 # Find AST nodes corresponding to each target.
920 #
921 # TODO: Don't rely on a set, since the items are in an unpredictable order.
922 while worklist:
923 processed |= worklist
924 current = worklist
925 worklist = set()
926 for target in current:
927 if target.startswith("<"):
928 module_id = module_prefix(graph, trigger_to_target(target))
929 if module_id:
930 ensure_deps_loaded(module_id, deps, graph)
931
932 worklist |= deps.get(target, set()) - processed
933 else:
934 module_id = module_prefix(graph, target)
935 if module_id is None:
936 # Deleted module.
937 continue
938 if module_id in up_to_date_modules:
939 # Already processed.
940 continue
941 if (
942 module_id not in manager.modules
943 or manager.modules[module_id].is_cache_skeleton
944 ):
945 # We haven't actually parsed and checked the module, so we don't have
946 # access to the actual nodes.
947 # Add it to the queue of files that need to be processed fully.
948 unloaded_files.add(module_id)
949 continue
950
951 if module_id not in result:
952 result[module_id] = set()
953 manager.log_fine_grained(f"process: {target}")
954 deferred, stale_proto = lookup_target(manager, target, module_id)
955 if stale_proto:
956 stale_protos.add(stale_proto)
957 result[module_id].update(deferred)

Callers 1

Calls 10

module_prefixFunction · 0.90
trigger_to_targetFunction · 0.90
setClass · 0.85
ensure_deps_loadedFunction · 0.85
lookup_targetFunction · 0.85
log_fine_grainedMethod · 0.80
startswithMethod · 0.45
getMethod · 0.45
addMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…