From bd67d4ad1c403f82bece1e9fba3df4f82f2aa360 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Mon, 13 Jan 2025 21:46:43 +0100 Subject: [PATCH] Run `ruff format` --- codespell_lib/_codespell.py | 10 ++++----- codespell_lib/tests/test_basic.py | 4 +--- codespell_lib/tests/test_dictionary.py | 30 +++++++++++++------------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index 8e9165ff95..794009bf56 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -58,8 +58,7 @@ # these may occur unescaped in URIs, and so we are more restrictive on the # endpoint. Emails are more restrictive, so the endpoint remains flexible. uri_regex_def = ( - "(\\b(?:https?|[ts]?ftp|file|git|smb)://[^\\s]+(?=$|\\s)|" - "\\b[\\w.%+-]+@[\\w.-]+\\b)" + "(\\b(?:https?|[ts]?ftp|file|git|smb)://[^\\s]+(?=$|\\s)|\\b[\\w.%+-]+@[\\w.-]+\\b)" ) inline_ignore_regex = re.compile(r"[^\w\s]\s?codespell:ignore\b(\s+(?P[\w,]*))?") USAGE = """ @@ -763,9 +762,9 @@ def ask_for_word_fix( return misspelling.fix, fix_case(wrongword, misspelling.data) line_ui = ( - f"{line[:match.start()]}" + f"{line[: match.start()]}" f"{colors.WWORD}{wrongword}{colors.DISABLE}" - f"{line[match.end():]}" + f"{line[match.end() :]}" ) if misspelling.fix and interactivity & 1: @@ -1057,8 +1056,7 @@ def parse_file( print_context(lines, i, context) if filename != "-": print( - f"{cfilename}:{cline}: {cwrongword} " - f"==> {crightword}{creason}" + f"{cfilename}:{cline}: {cwrongword} ==> {crightword}{creason}" ) elif options.stdin_single_line: print(f"{cline}: {cwrongword} ==> {crightword}{creason}") diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 69aac176f5..a6c05fc089 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -368,9 +368,7 @@ def test_ignore_words_with_cases( """Test case-sensitivity implemented for -I and -L options in #3272.""" bad_name = tmp_path / "MIS.txt" bad_name.write_text( - "1 MIS (Management Information System) 1\n" - "2 Les Mis (1980 musical) 2\n" - "3 mis 3\n" + "1 MIS (Management Information System) 1\n2 Les Mis (1980 musical) 2\n3 mis 3\n" ) assert cs.main(bad_name) == 3 assert cs.main(bad_name, "-f") == 4 diff --git a/codespell_lib/tests/test_dictionary.py b/codespell_lib/tests/test_dictionary.py index 617345d3b3..8270087116 100644 --- a/codespell_lib/tests/test_dictionary.py +++ b/codespell_lib/tests/test_dictionary.py @@ -144,9 +144,9 @@ def _check_err_rep( assert whitespace.search(err) is None, f"error {err!r} has whitespace" assert "," not in err, f"error {err!r} has a comma" assert len(rep) > 0, f"error {err}: correction {rep!r} must be non-empty" - assert not start_whitespace.match( - rep - ), f"error {err}: correction {rep!r} cannot start with whitespace" + assert not start_whitespace.match(rep), ( + f"error {err}: correction {rep!r} cannot start with whitespace" + ) _check_aspell(err, f"error {err!r}", in_aspell[0], fname, languages[0]) prefix = f"error {err}: correction {rep!r}" for regex, msg in ( @@ -166,9 +166,9 @@ def _check_err_rep( assert not regex.search(rep), msg % (prefix,) del msg if rep.count(","): - assert rep.endswith( - "," - ), f'error {err}: multiple corrections must end with trailing ","' + assert rep.endswith(","), ( + f'error {err}: multiple corrections must end with trailing ","' + ) reps = [r.strip() for r in rep.split(",")] reps = [r for r in reps if len(r)] for r in reps: @@ -185,9 +185,9 @@ def _check_err_rep( # we could ignore the case, but that would miss things like days of the # week which we want to be correct reps = [r.lower() for r in reps] - assert len(set(reps)) == len( - reps - ), f'error {err}: corrections "{rep}" are not (lower-case) unique' + assert len(set(reps)) == len(reps), ( + f'error {err}: corrections "{rep}" are not (lower-case) unique' + ) @pytest.mark.parametrize( @@ -307,18 +307,18 @@ def test_dictionary_looping( for line in fid: err, rep = line.split("->") err = err.lower() - assert ( - err not in this_err_dict - ), f"error {err!r} already exists in {short_fname}" + assert err not in this_err_dict, ( + f"error {err!r} already exists in {short_fname}" + ) rep = rep.rstrip("\n") reps = [r.strip() for r in rep.lower().split(",")] reps = [r for r in reps if len(r)] this_err_dict[err] = reps # 1. check the dict against itself (diagonal) 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}'" + assert word_regex.fullmatch(err), ( + f"error {err!r} does not match default word regex '{word_regex_def}'" + ) for r in reps: assert r not in this_err_dict, ( f"error {err}: correction {r} is an error itself "