diff --git a/pydocstringformatter/_configuration/toml_parsing.py b/pydocstringformatter/_configuration/toml_parsing.py index d684a414..65b8c036 100644 --- a/pydocstringformatter/_configuration/toml_parsing.py +++ b/pydocstringformatter/_configuration/toml_parsing.py @@ -45,11 +45,23 @@ def parse_toml_option( if value is True: return [action.option_strings[0]] return [] + if isinstance(action, argparse._StoreAction): if isinstance(value, int): value = str(value) return [action.option_strings[0], value] - return [] # pragma: no cover + + if isinstance(action, argparse._ExtendAction): # type: ignore[attr-defined] + out_args = [] + if isinstance(value, list): + for item in value: + out_args += [action.option_strings[0], item] + else: + out_args = [action.option_strings[0], value] + + return out_args + + raise NotImplementedError # pragma: no cover def parse_toml_file( diff --git a/tests/data/config/valid_toml_numpydoc/pyproject.toml b/tests/data/config/valid_toml_numpydoc/pyproject.toml new file mode 100644 index 00000000..a660220b --- /dev/null +++ b/tests/data/config/valid_toml_numpydoc/pyproject.toml @@ -0,0 +1,3 @@ +[tool.pydocstringformatter] +write = false +style = 'numpydoc' diff --git a/tests/data/config/valid_toml_numpydoc/test_package/numpydoc_style.py b/tests/data/config/valid_toml_numpydoc/test_package/numpydoc_style.py new file mode 100644 index 00000000..d7842d37 --- /dev/null +++ b/tests/data/config/valid_toml_numpydoc/test_package/numpydoc_style.py @@ -0,0 +1,3 @@ +def func(): + """ + A docstring""" diff --git a/tests/data/config/valid_toml_numpydoc_pep257/pyproject.toml b/tests/data/config/valid_toml_numpydoc_pep257/pyproject.toml new file mode 100644 index 00000000..33b3dbd2 --- /dev/null +++ b/tests/data/config/valid_toml_numpydoc_pep257/pyproject.toml @@ -0,0 +1,3 @@ +[tool.pydocstringformatter] +write = false +style = ["numpydoc","pep257"] diff --git a/tests/data/config/valid_toml_numpydoc_pep257/test_package/numpydoc_style.py b/tests/data/config/valid_toml_numpydoc_pep257/test_package/numpydoc_style.py new file mode 100644 index 00000000..d7842d37 --- /dev/null +++ b/tests/data/config/valid_toml_numpydoc_pep257/test_package/numpydoc_style.py @@ -0,0 +1,3 @@ +def func(): + """ + A docstring""" diff --git a/tests/data/config/valid_toml_pep257/pyproject.toml b/tests/data/config/valid_toml_pep257/pyproject.toml new file mode 100644 index 00000000..fa2fb1d3 --- /dev/null +++ b/tests/data/config/valid_toml_pep257/pyproject.toml @@ -0,0 +1,3 @@ +[tool.pydocstringformatter] +write = false +style = 'pep257' diff --git a/tests/data/config/valid_toml_pep257/test_package/numpydoc_style.py b/tests/data/config/valid_toml_pep257/test_package/numpydoc_style.py new file mode 100644 index 00000000..d7842d37 --- /dev/null +++ b/tests/data/config/valid_toml_pep257/test_package/numpydoc_style.py @@ -0,0 +1,3 @@ +def func(): + """ + A docstring""" diff --git a/tests/test_config.py b/tests/test_config.py index f3461f2e..9e6a07d1 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -255,3 +255,17 @@ def test_style_invalid_choice(self, capsys: pytest.CaptureFixture[str]) -> None: output = capsys.readouterr() assert not output.out assert "--style: invalid choice: 'invalid'" in output.err + + def test_style_in_toml(self, monkeypatch: pytest.MonkeyPatch) -> None: + """Test that the style argument works in the toml file.""" + monkeypatch.chdir(CONFIG_DATA / "valid_toml_numpydoc") + run = _Run(["test_package"]) + assert ["numpydoc"] == run.config.style + + monkeypatch.chdir(CONFIG_DATA / "valid_toml_pep257") + run = _Run(["test_package"]) + assert ["pep257"] == run.config.style + + monkeypatch.chdir(CONFIG_DATA / "valid_toml_numpydoc_pep257") + run = _Run(["test_package"]) + assert run.config.style == ["numpydoc", "pep257"]