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

Function compute_dependencies

mypy/solve.py:494–515  ·  view source on GitHub ↗

Compute dependencies between type variables induced by constraints. If we have a constraint like T <: List[S], we say that T depends on S, since we will need to solve for S first before we can solve for T.

(
    tvars: list[TypeVarId], graph: Graph, lowers: Bounds, uppers: Bounds
)

Source from the content-addressed store, hash-verified

492
493
494def compute_dependencies(
495 tvars: list[TypeVarId], graph: Graph, lowers: Bounds, uppers: Bounds
496) -> dict[TypeVarId, list[TypeVarId]]:
497 """Compute dependencies between type variables induced by constraints.
498
499 If we have a constraint like T <: List[S], we say that T depends on S, since
500 we will need to solve for S first before we can solve for T.
501 """
502 res = {}
503 for tv in tvars:
504 deps = set()
505 for lt in lowers[tv]:
506 deps |= get_vars(lt, tvars)
507 for ut in uppers[tv]:
508 deps |= get_vars(ut, tvars)
509 for other in tvars:
510 if other == tv:
511 continue
512 if (tv, other) in graph or (other, tv) in graph:
513 deps.add(other)
514 res[tv] = list(deps)
515 return res
516
517
518def check_linear(scc: set[TypeVarId], lowers: Bounds, uppers: Bounds) -> bool:

Callers 1

solve_with_dependentFunction · 0.85

Calls 4

setClass · 0.85
get_varsFunction · 0.85
listClass · 0.85
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…