diff --git a/pylintrc b/pylintrc new file mode 100644 index 0000000..afd255f --- /dev/null +++ b/pylintrc @@ -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 + diff --git a/python/run_matching.py b/python/run_matching.py index 3be4a14..c16c330 100755 --- a/python/run_matching.py +++ b/python/run_matching.py @@ -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) diff --git a/tests/generate/make_slow_graph.py b/tests/generate/make_slow_graph.py index 5899d5d..b0b2b86 100644 --- a/tests/generate/make_slow_graph.py +++ b/tests/generate/make_slow_graph.py @@ -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) diff --git a/tests/run_test.py b/tests/run_test.py index 3e684ed..4e3de45 100755 --- a/tests/run_test.py +++ b/tests/run_test.py @@ -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})",