Skip to content

Commit cfd2109

Browse files
Apply a selection of refurb rules (#3244)
1 parent a7ac7ca commit cfd2109

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

codespell_lib/_codespell.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -617,24 +617,23 @@ def parse_options(
617617

618618

619619
def parse_ignore_words_option(ignore_words_option: List[str]) -> Set[str]:
620-
ignore_words = set()
620+
ignore_words: Set[str] = set()
621621
if ignore_words_option:
622622
for comma_separated_words in ignore_words_option:
623-
for word in comma_separated_words.split(","):
624-
ignore_words.add(word.strip())
623+
ignore_words.update(
624+
word.strip() for word in comma_separated_words.split(",")
625+
)
625626
return ignore_words
626627

627628

628629
def build_exclude_hashes(filename: str, exclude_lines: Set[str]) -> None:
629630
with open(filename, encoding="utf-8") as f:
630-
for line in f:
631-
exclude_lines.add(line.rstrip())
631+
exclude_lines.update(line.rstrip() for line in f)
632632

633633

634634
def build_ignore_words(filename: str, ignore_words: Set[str]) -> None:
635635
with open(filename, encoding="utf-8") as f:
636-
for line in f:
637-
ignore_words.add(line.strip())
636+
ignore_words.update(line.strip() for line in f)
638637

639638

640639
def add_misspelling(
@@ -811,7 +810,7 @@ def apply_uri_ignore_words(
811810
) -> List[Match[str]]:
812811
if not uri_ignore_words:
813812
return check_matches
814-
for uri in re.findall(uri_regex, line):
813+
for uri in uri_regex.findall(line):
815814
for uri_word in extract_words(uri, word_regex, ignore_word_regex):
816815
if uri_word in uri_ignore_words:
817816
# determine/remove only the first among matches
@@ -1097,7 +1096,7 @@ def main(*args: str) -> int:
10971096
return EX_USAGE
10981097
uri_ignore_words = parse_ignore_words_option(options.uri_ignore_words_list)
10991098

1100-
dictionaries = options.dictionary if options.dictionary else ["-"]
1099+
dictionaries = options.dictionary or ["-"]
11011100

11021101
use_dictionaries = []
11031102
for dictionary in dictionaries:
@@ -1186,7 +1185,7 @@ def main(*args: str) -> int:
11861185
if os.path.isdir(filename):
11871186
for root, dirs, files in os.walk(filename):
11881187
if glob_match.match(root): # skip (absolute) directories
1189-
del dirs[:]
1188+
dirs.clear()
11901189
continue
11911190
if is_hidden(root, options.check_hidden): # dir itself hidden
11921191
continue

codespell_lib/tests/test_basic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ def test_ignore(
476476
assert cs.main("--skip=*ignoredir*", tmp_path) == 1
477477
assert cs.main("--skip=ignoredir", tmp_path) == 1
478478
assert cs.main("--skip=*ignoredir/bad*", tmp_path) == 1
479+
assert cs.main(f"--skip={tmp_path}", tmp_path) == 0
479480
badjs = tmp_path / "bad.js"
480481
copyfile(badtxt, badjs)
481482
assert cs.main("--skip=*.js", goodtxt, badtxt, badjs) == 1
@@ -1218,7 +1219,7 @@ def test_stdin(tmp_path: Path) -> None:
12181219
text = ""
12191220
for _ in range(input_file_lines):
12201221
text += "abandonned\n"
1221-
for single_line_per_error in [True, False]:
1222+
for single_line_per_error in (True, False):
12221223
args: Tuple[str, ...] = ()
12231224
if single_line_per_error:
12241225
args = ("--stdin-single-line",)

codespell_lib/tests/test_dictionary.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def _check_err_rep(
155155
), f"error {err}: correction {rep!r} cannot start with whitespace"
156156
_check_aspell(err, f"error {err!r}", in_aspell[0], fname, languages[0])
157157
prefix = f"error {err}: correction {rep!r}"
158-
for regex, msg in [
158+
for regex, msg in (
159159
(start_comma, "%s starts with a comma"),
160160
(
161161
whitespace_comma,
@@ -168,7 +168,7 @@ def _check_err_rep(
168168
(comma_without_space, "%s contains a comma *not* followed by a space"),
169169
(whitespace_end, "%s has a trailing space"),
170170
(single_comma, "%s has a single entry but contains a trailing comma"),
171-
]:
171+
):
172172
assert not regex.search(rep), msg % (prefix,)
173173
del msg
174174
if rep.count(","):

0 commit comments

Comments
 (0)