1
0
Fork 0

Pylint cleanups

This commit is contained in:
Joris van Rantwijk 2023-03-11 23:21:10 +01:00
parent dd24776149
commit b8391ea319
4 changed files with 31 additions and 7 deletions

20
pylintrc Normal file
View File

@ -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

View File

@ -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]]:
"""Read a graph from file or stdin."""
if filename:
with open(filename, "r") as f:
with open(filename, "r", encoding="ascii") as f:
try:
return read_dimacs_graph(f)
except ValueError as exc:
@ -140,7 +140,7 @@ def read_dimacs_matching_file(
filename: str
) -> tuple[int|float, list[tuple[int, int]]]:
"""Read a matching from file."""
with open(filename, "r") as f:
with open(filename, "r", encoding="ascii") as f:
try:
return read_dimacs_matching(f)
except ValueError as exc:
@ -170,7 +170,7 @@ def write_dimacs_matching_file(
) -> None:
"""Write a matching to file or stdout."""
if filename:
with open(filename, "x") as f:
with open(filename, "x", encoding="ascii") as f:
write_dimacs_matching(f, weight, pairs)
else:
write_dimacs_matching(sys.stdout, weight, pairs)

View File

@ -19,6 +19,7 @@ count_delta_step = [0]
def patch_matching_code() -> None:
"""Patch the matching code to count events."""
# pylint: disable=import-outside-toplevel,protected-access
import mwmatching
@ -44,6 +45,8 @@ def run_max_weight_matching(
edges: list[tuple[int, int, int]]
) -> tuple[list[tuple[int, int]], int, int]:
"""Run the matching algorithm and count subroutine calls."""
# pylint: disable=import-outside-toplevel
import mwmatching
count_make_blossom[0] = 0
@ -322,7 +325,7 @@ def main() -> int:
assert False
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)} "
f"nblossom={num_blossom} ndelta={num_delta}",
file=sys.stderr)

View File

@ -45,6 +45,7 @@ class Matching(NamedTuple):
class RunStatus(enum.IntEnum):
"""Result categories for running a solver."""
OK = 0
FAILED = 1
WRONG_ANSWER = 2
@ -440,7 +441,7 @@ class WmatchSolver(Solver):
y = int(words[1])
except ValueError:
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))
return Matching(pairs)
@ -660,7 +661,7 @@ def test_input(
for filename in files:
try:
with open(filename, "r") as f:
with open(filename, "r", encoding="ascii") as f:
graph = read_dimacs_graph(f)
except (OSError, ValueError) as exc:
print(f"ERROR: Can not read graph {filename!r} ({exc})",
@ -671,7 +672,7 @@ def test_input(
if verify:
reffile = os.path.splitext(filename)[0] + ".out"
try:
with open(reffile, "r") as f:
with open(reffile, "r", encoding="ascii") as f:
(gold_weight, _matching) = read_dimacs_matching(f)
except (OSError, ValueError) as exc:
print(f"ERROR: Can not read matching {reffile!r} ({exc})",