def get_upstream_end_to_tns(ends_to_topological_nodes: List[Tuple[(PowerTransformerEnd, T)]]) -> List[Tuple[(PowerTransformerEnd, T)]]:
    return [(end, tn) for (end, tn) in ends_to_topological_nodes if ((tn is not None) and (end is not None) and (end.terminal.traced_phases.direction_normal(SinglePhaseKind.A).has(PhaseDirection.IN) or end.terminal.traced_phases.direction_normal(SinglePhaseKind.B).has(PhaseDirection.IN) or end.terminal.traced_phases.direction_normal(SinglePhaseKind.C).has(PhaseDirection.IN)))]
def get_upstream_end_to_tns(ends_to_topological_nodes: List[Tuple[(PowerTransformerEnd, T)]]) -> List[Tuple[(PowerTransformerEnd, T)]]:
    return [(end, tn) for (end, tn) in ends_to_topological_nodes if ((tn is not None) and (end is not None) and (end.terminal.traced_phases.direction_normal(SinglePhaseKind.A).has(PhaseDirection.IN) or end.terminal.traced_phases.direction_normal(SinglePhaseKind.B).has(PhaseDirection.IN) or end.terminal.traced_phases.direction_normal(SinglePhaseKind.C).has(PhaseDirection.IN)))]