Skip to content

Commit 6668a62

Browse files
resolve ruff lint errs
1 parent 2578bfd commit 6668a62

2 files changed

Lines changed: 29 additions & 20 deletions

File tree

codespell_lib/_codespell.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,27 @@ def _usage_error(parser: argparse.ArgumentParser, message: str) -> int:
12451245
return EX_USAGE
12461246

12471247

1248+
def _select_builtin_dictionary(builtin_option: str) -> list[str]:
1249+
use = sorted(set(builtin_option.split(",")))
1250+
if "all" in use:
1251+
use = [u for u in use if u != "all"] + [
1252+
builtin[0] for builtin in _builtin_dictionaries
1253+
]
1254+
use = sorted(set(use))
1255+
1256+
use_dictionaries = []
1257+
for u in use:
1258+
for builtin in _builtin_dictionaries:
1259+
if builtin[0] == u:
1260+
use_dictionaries.append(
1261+
os.path.join(_data_root, f"dictionary{builtin[2]}.txt")
1262+
)
1263+
break
1264+
else:
1265+
raise KeyError(u)
1266+
return use_dictionaries
1267+
1268+
12481269
def main(*args: str) -> int:
12491270
"""Contains flow control"""
12501271
try:
@@ -1338,25 +1359,13 @@ def main(*args: str) -> int:
13381359
use_dictionaries = []
13391360
for dictionary in dictionaries:
13401361
if dictionary == "-":
1341-
# figure out which builtin dictionaries to use
1342-
use = sorted(set(options.builtin.split(",")))
1343-
if "all" in use:
1344-
use = [u for u in use if u != "all"] + [
1345-
builtin[0] for builtin in _builtin_dictionaries
1346-
]
1347-
use = sorted(set(use))
1348-
for u in use:
1349-
for builtin in _builtin_dictionaries:
1350-
if builtin[0] == u:
1351-
use_dictionaries.append(
1352-
os.path.join(_data_root, f"dictionary{builtin[2]}.txt")
1353-
)
1354-
break
1355-
else:
1356-
return _usage_error(
1357-
parser,
1358-
f"ERROR: Unknown builtin dictionary: {u}",
1359-
)
1362+
try:
1363+
use_dictionaries.extend(_select_builtin_dictionary(options.builtin))
1364+
except KeyError as e:
1365+
return _usage_error(
1366+
parser,
1367+
f"ERROR: Unknown builtin dictionary: {e.args[0]}",
1368+
)
13601369
else:
13611370
if not os.path.isfile(dictionary):
13621371
return _usage_error(

codespell_lib/tests/test_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
import codespell_lib as cs_
1818
from codespell_lib._codespell import (
19-
_builtin_dictionaries,
2019
EX_CONFIG,
2120
EX_DATAERR,
2221
EX_OK,
2322
EX_USAGE,
23+
_builtin_dictionaries,
2424
uri_regex_def,
2525
)
2626

0 commit comments

Comments
 (0)