1
0
Fork 0

Remove redundant type annotations "int|float"

This commit is contained in:
Joris van Rantwijk 2024-07-07 10:36:08 +02:00
parent b2d4de41f9
commit f2e8ca1357
1 changed files with 12 additions and 12 deletions

View File

@ -18,7 +18,7 @@ from mwmatching import (maximum_weight_matching,
adjust_weights_for_maximum_cardinality_matching) adjust_weights_for_maximum_cardinality_matching)
def parse_int_or_float(s: str) -> int|float: def parse_int_or_float(s: str) -> float:
"""Convert a string to integer or float value.""" """Convert a string to integer or float value."""
try: try:
return int(s) return int(s)
@ -27,7 +27,7 @@ def parse_int_or_float(s: str) -> int|float:
return float(s) return float(s)
def read_dimacs_graph(f: TextIO) -> list[tuple[int, int, int|float]]: def read_dimacs_graph(f: TextIO) -> list[tuple[int, int, float]]:
"""Read a graph in DIMACS edge list format.""" """Read a graph in DIMACS edge list format."""
edges: list[tuple[int, int, float]] = [] edges: list[tuple[int, int, float]] = []
@ -70,7 +70,7 @@ def read_dimacs_graph(f: TextIO) -> list[tuple[int, int, int|float]]:
return edges return edges
def read_dimacs_graph_file(filename: str) -> list[tuple[int, int, int|float]]: def read_dimacs_graph_file(filename: str) -> list[tuple[int, int, float]]:
"""Read a graph from file or stdin.""" """Read a graph from file or stdin."""
if filename: if filename:
with open(filename, "r", encoding="ascii") as f: with open(filename, "r", encoding="ascii") as f:
@ -87,11 +87,11 @@ def read_dimacs_graph_file(filename: str) -> list[tuple[int, int, int|float]]:
def read_dimacs_matching( def read_dimacs_matching(
f: TextIO f: TextIO
) -> tuple[int|float, list[tuple[int, int]]]: ) -> tuple[float, list[tuple[int, int]]]:
"""Read a matching solution in DIMACS format.""" """Read a matching solution in DIMACS format."""
have_weight = False have_weight = False
weight: int|float = 0 weight: float = 0
pairs: list[tuple[int, int]] = [] pairs: list[tuple[int, int]] = []
for line in f: for line in f:
@ -138,7 +138,7 @@ def read_dimacs_matching(
def read_dimacs_matching_file( def read_dimacs_matching_file(
filename: str filename: str
) -> tuple[int|float, list[tuple[int, int]]]: ) -> tuple[float, list[tuple[int, int]]]:
"""Read a matching from file.""" """Read a matching from file."""
with open(filename, "r", encoding="ascii") as f: with open(filename, "r", encoding="ascii") as f:
try: try:
@ -149,7 +149,7 @@ def read_dimacs_matching_file(
def write_dimacs_matching( def write_dimacs_matching(
f: TextIO, f: TextIO,
weight: int|float, weight: float,
pairs: list[tuple[int, int]] pairs: list[tuple[int, int]]
) -> None: ) -> None:
"""Write a matching solution in DIMACS format.""" """Write a matching solution in DIMACS format."""
@ -165,7 +165,7 @@ def write_dimacs_matching(
def write_dimacs_matching_file( def write_dimacs_matching_file(
filename: str, filename: str,
weight: int|float, weight: float,
pairs: list[tuple[int, int]] pairs: list[tuple[int, int]]
) -> None: ) -> None:
"""Write a matching to file or stdout.""" """Write a matching to file or stdout."""
@ -177,15 +177,15 @@ def write_dimacs_matching_file(
def calc_matching_weight( def calc_matching_weight(
edges: list[tuple[int, int, int|float]], edges: list[tuple[int, int, float]],
pairs: list[tuple[int, int]] pairs: list[tuple[int, int]]
) -> int|float: ) -> float:
"""Verify that the matching is valid and calculate its weight. """Verify that the matching is valid and calculate its weight.
Matched pairs are assumed to be in the same order as edges. Matched pairs are assumed to be in the same order as edges.
""" """
weight: int|float = 0 weight: float = 0
edge_pos = 0 edge_pos = 0
for pair in pairs: for pair in pairs:
@ -267,7 +267,7 @@ def verify_matching(filename: str, maxcard: bool, wfactor: float) -> bool:
edges = read_dimacs_graph_file(filename) edges = read_dimacs_graph_file(filename)
(gold_weight, gold_pairs) = read_dimacs_matching_file(matching_filename) (gold_weight, gold_pairs) = read_dimacs_matching_file(matching_filename)
edges_adj: Sequence[tuple[int, int, int|float]] = edges edges_adj: Sequence[tuple[int, int, float]] = edges
if wfactor != 1.0: if wfactor != 1.0:
if wfactor.is_integer(): if wfactor.is_integer():