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

Function apply_class_plugin_hooks

mypy/semanal_main.py:444–477  ·  view source on GitHub ↗

Apply class plugin hooks within a SCC. We run these after to the main semantic analysis so that the hooks don't need to deal with incomplete definitions such as placeholder types. Note that some hooks incorrectly run during the main semantic analysis pass, for historical reason

(graph: Graph, scc: list[str], errors: Errors)

Source from the content-addressed store, hash-verified

442
443
444def apply_class_plugin_hooks(graph: Graph, scc: list[str], errors: Errors) -> None:
445 """Apply class plugin hooks within a SCC.
446
447 We run these after to the main semantic analysis so that the hooks
448 don't need to deal with incomplete definitions such as placeholder
449 types.
450
451 Note that some hooks incorrectly run during the main semantic
452 analysis pass, for historical reasons.
453 """
454 num_passes = 0
455 incomplete = True
456 # If we encounter a base class that has not been processed, we'll run another
457 # pass. This should eventually reach a fixed point.
458 while incomplete:
459 assert num_passes < 10, "Internal error: too many class plugin hook passes"
460 num_passes += 1
461 incomplete = False
462 for module in scc:
463 state = graph[module]
464 tree = state.tree
465 assert tree
466 with state.wrap_context():
467 for _, node, _ in tree.local_definitions():
468 if isinstance(node.node, TypeInfo):
469 if not apply_hooks_to_class(
470 state.manager.semantic_analyzer,
471 module,
472 node.node,
473 state.options,
474 tree,
475 errors,
476 ):
477 incomplete = True
478
479
480def apply_hooks_to_class(

Callers 2

Calls 4

isinstanceFunction · 0.85
apply_hooks_to_classFunction · 0.85
wrap_contextMethod · 0.80
local_definitionsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…