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
)
| 492 | |
| 493 | |
| 494 | def 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 | |
| 518 | def check_linear(scc: set[TypeVarId], lowers: Bounds, uppers: Bounds) -> bool: |
no test coverage detected
searching dependent graphs…