Skip to content

Commit

Permalink
Run ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriPapadopoulos committed Jan 13, 2025
1 parent 0bcdc10 commit bd67d4a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
10 changes: 4 additions & 6 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<words>[\w,]*))?")
USAGE = """
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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}")
Expand Down
4 changes: 1 addition & 3 deletions codespell_lib/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions codespell_lib/tests/test_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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:
Expand All @@ -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(
Expand Down Expand Up @@ -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 "
Expand Down

0 comments on commit bd67d4a

Please sign in to comment.