Skip to content

Commit 81e47b5

Browse files
Enable lists in TOML config file (#3294)
1 parent 0353c3e commit 81e47b5

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

codespell_lib/_codespell.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,11 @@ def _split_lines(self, text: str, width: int) -> List[str]:
325325

326326
def _toml_to_parseconfig(toml_dict: Dict[str, Any]) -> Dict[str, Any]:
327327
"""Convert a dict read from a TOML file to the parseconfig.read_dict() format."""
328-
return {k: "" if v is True else v for k, v in toml_dict.items() if v is not False}
328+
return {
329+
k: "" if v is True else ",".join(v) if isinstance(v, list) else v
330+
for k, v in toml_dict.items()
331+
if v is not False
332+
}
329333

330334

331335
def _supports_ansi_colors() -> bool:

codespell_lib/tests/test_basic.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ def test_ill_formed_ini_config_file(
11501150
assert "ill-formed config file" in stderr
11511151

11521152

1153-
@pytest.mark.parametrize("kind", ("toml", "cfg"))
1153+
@pytest.mark.parametrize("kind", ("cfg", "toml", "toml_list"))
11541154
def test_config_toml(
11551155
tmp_path: Path,
11561156
capsys: pytest.CaptureFixture[str],
@@ -1182,7 +1182,7 @@ def test_config_toml(
11821182
count =
11831183
"""
11841184
)
1185-
else:
1185+
elif kind == "toml":
11861186
assert kind == "toml"
11871187
if sys.version_info < (3, 11):
11881188
pytest.importorskip("tomli")
@@ -1194,6 +1194,20 @@ def test_config_toml(
11941194
skip = 'bad.txt,whatever.txt'
11951195
check-filenames = false
11961196
count = true
1197+
"""
1198+
)
1199+
else:
1200+
assert kind == "toml_list"
1201+
if sys.version_info < (3, 11):
1202+
pytest.importorskip("tomli")
1203+
tomlfile = tmp_path / "pyproject.toml"
1204+
args = ("--toml", tomlfile)
1205+
tomlfile.write_text(
1206+
"""\
1207+
[tool.codespell]
1208+
skip = ['bad.txt', 'whatever.txt']
1209+
check-filenames = false
1210+
count = true
11971211
"""
11981212
)
11991213

0 commit comments

Comments
 (0)