Skip to content

Commit 60a82b3

Browse files
jspaezpPierre-SassoulasDanielNoord
authored
Fixed toml parser for style option (#156)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com> Co-authored-by: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
1 parent c749fc6 commit 60a82b3

File tree

8 files changed

+45
-1
lines changed

8 files changed

+45
-1
lines changed

pydocstringformatter/_configuration/toml_parsing.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,23 @@ def parse_toml_option(
4545
if value is True:
4646
return [action.option_strings[0]]
4747
return []
48+
4849
if isinstance(action, argparse._StoreAction):
4950
if isinstance(value, int):
5051
value = str(value)
5152
return [action.option_strings[0], value]
52-
return [] # pragma: no cover
53+
54+
if isinstance(action, argparse._ExtendAction): # type: ignore[attr-defined]
55+
out_args = []
56+
if isinstance(value, list):
57+
for item in value:
58+
out_args += [action.option_strings[0], item]
59+
else:
60+
out_args = [action.option_strings[0], value]
61+
62+
return out_args
63+
64+
raise NotImplementedError # pragma: no cover
5365

5466

5567
def parse_toml_file(
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[tool.pydocstringformatter]
2+
write = false
3+
style = 'numpydoc'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def func():
2+
"""
3+
A docstring"""
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[tool.pydocstringformatter]
2+
write = false
3+
style = ["numpydoc","pep257"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def func():
2+
"""
3+
A docstring"""
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[tool.pydocstringformatter]
2+
write = false
3+
style = 'pep257'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def func():
2+
"""
3+
A docstring"""

tests/test_config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,17 @@ def test_style_invalid_choice(self, capsys: pytest.CaptureFixture[str]) -> None:
255255
output = capsys.readouterr()
256256
assert not output.out
257257
assert "--style: invalid choice: 'invalid'" in output.err
258+
259+
def test_style_in_toml(self, monkeypatch: pytest.MonkeyPatch) -> None:
260+
"""Test that the style argument works in the toml file."""
261+
monkeypatch.chdir(CONFIG_DATA / "valid_toml_numpydoc")
262+
run = _Run(["test_package"])
263+
assert ["numpydoc"] == run.config.style
264+
265+
monkeypatch.chdir(CONFIG_DATA / "valid_toml_pep257")
266+
run = _Run(["test_package"])
267+
assert ["pep257"] == run.config.style
268+
269+
monkeypatch.chdir(CONFIG_DATA / "valid_toml_numpydoc_pep257")
270+
run = _Run(["test_package"])
271+
assert run.config.style == ["numpydoc", "pep257"]

0 commit comments

Comments
 (0)