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"] diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 74e10404e1..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 @@ -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 @@ -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 @@ -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) 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}" diff --git a/pyproject.toml b/pyproject.toml index 1c5f6c103a..69d7c80d8a 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,36 @@ select = [ "W", "YTT", ] +ignore = [ + "ANN101", + "B904", + "PLR0914", + "PLR6201", + "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