Pylint cleanups
This commit is contained in:
parent
dd24776149
commit
b8391ea319
|
@ -0,0 +1,20 @@
|
||||||
|
|
||||||
|
[MESSAGES CONTROL]
|
||||||
|
|
||||||
|
disable=consider-using-in,
|
||||||
|
duplicate-code,
|
||||||
|
invalid-name,
|
||||||
|
no-else-return,
|
||||||
|
superfluous-parens,
|
||||||
|
too-few-public-methods,
|
||||||
|
too-many-arguments,
|
||||||
|
too-many-branches,
|
||||||
|
too-many-instance-attributes,
|
||||||
|
too-many-lines,
|
||||||
|
too-many-locals,
|
||||||
|
too-many-nested-blocks,
|
||||||
|
too-many-public-methods,
|
||||||
|
too-many-return-statements,
|
||||||
|
too-many-statements,
|
||||||
|
unnecessary-pass
|
||||||
|
|
|
@ -73,7 +73,7 @@ def read_dimacs_graph(f: TextIO) -> list[tuple[int, int, int|float]]:
|
||||||
def read_dimacs_graph_file(filename: str) -> list[tuple[int, int, int|float]]:
|
def read_dimacs_graph_file(filename: str) -> list[tuple[int, 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") as f:
|
with open(filename, "r", encoding="ascii") as f:
|
||||||
try:
|
try:
|
||||||
return read_dimacs_graph(f)
|
return read_dimacs_graph(f)
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
|
@ -140,7 +140,7 @@ def read_dimacs_matching_file(
|
||||||
filename: str
|
filename: str
|
||||||
) -> tuple[int|float, list[tuple[int, int]]]:
|
) -> tuple[int|float, list[tuple[int, int]]]:
|
||||||
"""Read a matching from file."""
|
"""Read a matching from file."""
|
||||||
with open(filename, "r") as f:
|
with open(filename, "r", encoding="ascii") as f:
|
||||||
try:
|
try:
|
||||||
return read_dimacs_matching(f)
|
return read_dimacs_matching(f)
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
|
@ -170,7 +170,7 @@ def write_dimacs_matching_file(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Write a matching to file or stdout."""
|
"""Write a matching to file or stdout."""
|
||||||
if filename:
|
if filename:
|
||||||
with open(filename, "x") as f:
|
with open(filename, "x", encoding="ascii") as f:
|
||||||
write_dimacs_matching(f, weight, pairs)
|
write_dimacs_matching(f, weight, pairs)
|
||||||
else:
|
else:
|
||||||
write_dimacs_matching(sys.stdout, weight, pairs)
|
write_dimacs_matching(sys.stdout, weight, pairs)
|
||||||
|
|
|
@ -19,6 +19,7 @@ count_delta_step = [0]
|
||||||
|
|
||||||
def patch_matching_code() -> None:
|
def patch_matching_code() -> None:
|
||||||
"""Patch the matching code to count events."""
|
"""Patch the matching code to count events."""
|
||||||
|
# pylint: disable=import-outside-toplevel,protected-access
|
||||||
|
|
||||||
import mwmatching
|
import mwmatching
|
||||||
|
|
||||||
|
@ -44,6 +45,8 @@ def run_max_weight_matching(
|
||||||
edges: list[tuple[int, int, int]]
|
edges: list[tuple[int, int, int]]
|
||||||
) -> tuple[list[tuple[int, int]], int, int]:
|
) -> tuple[list[tuple[int, int]], int, int]:
|
||||||
"""Run the matching algorithm and count subroutine calls."""
|
"""Run the matching algorithm and count subroutine calls."""
|
||||||
|
# pylint: disable=import-outside-toplevel
|
||||||
|
|
||||||
import mwmatching
|
import mwmatching
|
||||||
|
|
||||||
count_make_blossom[0] = 0
|
count_make_blossom[0] = 0
|
||||||
|
@ -322,7 +325,7 @@ def main() -> int:
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
if args.check:
|
if args.check:
|
||||||
(pairs, num_blossom, num_delta) = run_max_weight_matching(edges)
|
(_pairs, num_blossom, num_delta) = run_max_weight_matching(edges)
|
||||||
print(f"n={args.n} m={len(edges)} "
|
print(f"n={args.n} m={len(edges)} "
|
||||||
f"nblossom={num_blossom} ndelta={num_delta}",
|
f"nblossom={num_blossom} ndelta={num_delta}",
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
|
|
|
@ -45,6 +45,7 @@ class Matching(NamedTuple):
|
||||||
|
|
||||||
|
|
||||||
class RunStatus(enum.IntEnum):
|
class RunStatus(enum.IntEnum):
|
||||||
|
"""Result categories for running a solver."""
|
||||||
OK = 0
|
OK = 0
|
||||||
FAILED = 1
|
FAILED = 1
|
||||||
WRONG_ANSWER = 2
|
WRONG_ANSWER = 2
|
||||||
|
@ -440,7 +441,7 @@ class WmatchSolver(Solver):
|
||||||
y = int(words[1])
|
y = int(words[1])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise SolverError("Invalid format in solver output") from None
|
raise SolverError("Invalid format in solver output") from None
|
||||||
if x > 0 and x < y:
|
if 0 < x < y:
|
||||||
pairs.append((x - 1, y - 1))
|
pairs.append((x - 1, y - 1))
|
||||||
|
|
||||||
return Matching(pairs)
|
return Matching(pairs)
|
||||||
|
@ -660,7 +661,7 @@ def test_input(
|
||||||
for filename in files:
|
for filename in files:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(filename, "r") as f:
|
with open(filename, "r", encoding="ascii") as f:
|
||||||
graph = read_dimacs_graph(f)
|
graph = read_dimacs_graph(f)
|
||||||
except (OSError, ValueError) as exc:
|
except (OSError, ValueError) as exc:
|
||||||
print(f"ERROR: Can not read graph {filename!r} ({exc})",
|
print(f"ERROR: Can not read graph {filename!r} ({exc})",
|
||||||
|
@ -671,7 +672,7 @@ def test_input(
|
||||||
if verify:
|
if verify:
|
||||||
reffile = os.path.splitext(filename)[0] + ".out"
|
reffile = os.path.splitext(filename)[0] + ".out"
|
||||||
try:
|
try:
|
||||||
with open(reffile, "r") as f:
|
with open(reffile, "r", encoding="ascii") as f:
|
||||||
(gold_weight, _matching) = read_dimacs_matching(f)
|
(gold_weight, _matching) = read_dimacs_matching(f)
|
||||||
except (OSError, ValueError) as exc:
|
except (OSError, ValueError) as exc:
|
||||||
print(f"ERROR: Can not read matching {reffile!r} ({exc})",
|
print(f"ERROR: Can not read matching {reffile!r} ({exc})",
|
||||||
|
|
Loading…
Reference in New Issue