From 62f28de8ea5a2686deccda506559128a7ed0b953 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:37:35 +0200 Subject: [PATCH 1/6] Update ruff settings Disable deprecated/problematic rules. --- pyproject.toml | 51 +++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1c5f6c103a..ff47f1d38c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -109,29 +109,6 @@ filterwarnings = ["error"] line-length = 88 [tool.ruff.lint] -ignore = [ - "ANN101", - "B904", - "PLW2901", - "RET505", - "SIM105", - "SIM115", - # https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules - "W191", - "E111", - "E114", - "E117", - "D206", - "D300", - "Q000", - "Q001", - "Q002", - "Q003", - "COM812", - "COM819", - "ISC001", - "ISC002", -] select = [ "A", "ANN", @@ -157,6 +134,34 @@ select = [ "W", "YTT", ] +ignore = [ + "ANN101", + "B904", + "PLW2901", + "PT004", # deprecated + "PT005", # deprecated + "RET505", + "S404", + "SIM105", + "SIM115", + "UP027", # deprecated + "UP038", # https://github.com/astral-sh/ruff/issues/7871 + # https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules + "W191", + "E111", + "E114", + "E117", + "D206", + "D300", + "Q000", + "Q001", + "Q002", + "Q003", + "COM812", + "COM819", + "ISC001", + "ISC002", +] [tool.ruff.lint.mccabe] max-complexity = 45 From 701bafed2600fa7f7ac0e8e1b04ffe2d33d948b1 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:39:15 +0200 Subject: [PATCH 2/6] Apply ruff preview rule RUF022 RUF022 `__all__` is not sorted --- codespell_lib/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codespell_lib/__init__.py b/codespell_lib/__init__.py index c5dc784cb8..621e36d8de 100644 --- a/codespell_lib/__init__.py +++ b/codespell_lib/__init__.py @@ -1,4 +1,4 @@ from ._codespell import _script_main, main from ._version import __version__ # type: ignore[import-not-found] -__all__ = ["_script_main", "main", "__version__"] +__all__ = ["__version__", "_script_main", "main"] From 1b300eb0474b931b6fd50331d7c62697fed49f2f Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:42:11 +0200 Subject: [PATCH 3/6] Apply ruff/Pylint preview rule PLC0206 PLC0206 Extracting value from dictionary without calling `.items()` --- codespell_lib/tests/test_dictionary.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/codespell_lib/tests/test_dictionary.py b/codespell_lib/tests/test_dictionary.py index 60b14826d2..85a6b86b7e 100644 --- a/codespell_lib/tests/test_dictionary.py +++ b/codespell_lib/tests/test_dictionary.py @@ -315,11 +315,11 @@ def test_dictionary_looping( reps = [r for r in reps if len(r)] this_err_dict[err] = reps # 1. check the dict against itself (diagonal) - for err in this_err_dict: + for err, reps in this_err_dict.items(): assert word_regex.fullmatch( err ), f"error {err!r} does not match default word regex '{word_regex_def}'" - for r in this_err_dict[err]: + for r in reps: assert r not in this_err_dict, ( f"error {err}: correction {r} is an error itself " f"in the same dictionary file {short_fname}" @@ -337,12 +337,12 @@ def test_dictionary_looping( # 2. check corrections in this dict against other dicts (upper) pair = (short_fname, other_fname) if pair not in allowed_dups: - for err in this_err_dict: + for err, reps in this_err_dict.items(): assert err not in other_err_dict, ( f"error {err!r} in dictionary {short_fname} " f"already exists in dictionary {other_fname}" ) - for r in this_err_dict[err]: + for r in reps: assert r not in other_err_dict, ( f"error {err}: correction {r} from dictionary {short_fname} " f"is an error itself in dictionary {other_fname}" From e7ba4cd1740d33e440d01592231b7a429368d4f2 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:44:09 +0200 Subject: [PATCH 4/6] Apply ruff/Pylint preview rule PLW1514 PLW1514 `open` in text mode without explicit `encoding` argument --- codespell_lib/tests/test_basic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 74e10404e1..f67964cb92 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -464,7 +464,7 @@ def test_inline_ignores( expected_error_count: int, ) -> None: d = str(tmpdir) - with open(op.join(d, "bad.txt"), "w") as f: + with open(op.join(d, "bad.txt"), "w", encoding="utf-8") as f: f.write(content) assert cs.main(d) == expected_error_count @@ -1234,7 +1234,7 @@ def test_quiet_level_32( d = tmp_path / "files" d.mkdir() conf = str(tmp_path / "setup.cfg") - with open(conf, "w") as f: + with open(conf, "w", encoding="utf-8") as f: # It must contain a "codespell" section. f.write("[codespell]\n") args = ("--config", conf) @@ -1263,7 +1263,7 @@ def test_ill_formed_ini_config_file( d = tmp_path / "files" d.mkdir() conf = str(tmp_path / "setup.cfg") - with open(conf, "w") as f: + with open(conf, "w", encoding="utf-8") as f: # It should contain but lacks a section. f.write("foobar =\n") args = ("--config", conf) From e44ea6978712f85cfe8e8442fb0efcbc24e79bc2 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:45:34 +0200 Subject: [PATCH 5/6] Disable ruff/Pylint preview rules They do not seem worth applying in existing code. --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index ff47f1d38c..69d7c80d8a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -137,6 +137,8 @@ select = [ ignore = [ "ANN101", "B904", + "PLR0914", + "PLR6201", "PLW2901", "PT004", # deprecated "PT005", # deprecated From fb126f3fd069160d44ba3930cf13f3c862e1929e Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:48:13 +0200 Subject: [PATCH 6/6] Apply ruff/Pyflakes preview rule F841 F841 Local variable is assigned to but never used --- codespell_lib/tests/test_basic.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index f67964cb92..69aac176f5 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -217,12 +217,12 @@ def test_permission_error( fname.write_text("abandonned\n") result = cs.main(fname, std=True) assert isinstance(result, tuple) - code, _, stderr = result + _, _, stderr = result assert "WARNING:" not in stderr fname.chmod(0o000) result = cs.main(fname, std=True) assert isinstance(result, tuple) - code, _, stderr = result + _, _, stderr = result assert "WARNING:" in stderr @@ -772,7 +772,7 @@ def _helper_test_case_handling_in_fixes( fname.write_text("early adoptor\n") result = cs.main("-D", dictionary_name, fname, std=True) assert isinstance(result, tuple) - code, stdout, _ = result + _, stdout, _ = result # all suggested fixes must be lowercase too assert "adopter, adaptor" in stdout # the reason, if any, must not be modified @@ -783,7 +783,7 @@ def _helper_test_case_handling_in_fixes( fname.write_text("Early Adoptor\n") result = cs.main("-D", dictionary_name, fname, std=True) assert isinstance(result, tuple) - code, stdout, _ = result + _, stdout, _ = result # all suggested fixes must be capitalized too assert "Adopter, Adaptor" in stdout # the reason, if any, must not be modified @@ -794,7 +794,7 @@ def _helper_test_case_handling_in_fixes( fname.write_text("EARLY ADOPTOR\n") result = cs.main("-D", dictionary_name, fname, std=True) assert isinstance(result, tuple) - code, stdout, _ = result + _, stdout, _ = result # all suggested fixes must be uppercase too assert "ADOPTER, ADAPTOR" in stdout # the reason, if any, must not be modified @@ -805,7 +805,7 @@ def _helper_test_case_handling_in_fixes( fname.write_text("EaRlY AdOpToR\n") result = cs.main("-D", dictionary_name, fname, std=True) assert isinstance(result, tuple) - code, stdout, _ = result + _, stdout, _ = result # all suggested fixes should be lowercase assert "adopter, adaptor" in stdout # the reason, if any, must not be modified