Skip to content
8 changes: 8 additions & 0 deletions pydocstringformatter/_configuration/toml_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import sys
from typing import Any

from pydocstringformatter._configuration.boolean_option_action import (
BooleanOptionalAction,
)
from pydocstringformatter._utils.exceptions import TomlParsingError, UnrecognizedOption

if sys.version_info <= (3, 11):
Expand Down Expand Up @@ -41,6 +44,11 @@ def parse_toml_option(
except KeyError:
raise UnrecognizedOption(f"Don't recognize option {opt}") from exc

if isinstance(action, BooleanOptionalAction):
index = action.option_strings.index(f"--{opt}")
option = action.option_strings[index]
return [option]

if isinstance(action, argparse._StoreTrueAction):
if value is True:
return [action.option_strings[0]]
Expand Down
6 changes: 6 additions & 0 deletions tests/data/config/valid_toml_boolopt/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[tool.pydocstringformatter]
write = false
style = ["numpydoc"]
strip-whitespaces = true
split-summary-body = false
no-numpydoc-section-hyphen-length = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def func():
"""
A docstring"""
10 changes: 10 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,13 @@ def test_style_in_toml(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.chdir(CONFIG_DATA / "valid_toml_numpydoc_pep257")
run = _Run(["test_package"])
assert run.config.style == ["numpydoc", "pep257"]

def test_boolopt_in_toml(self, monkeypatch: pytest.MonkeyPatch) -> None:
"""Test that arguments of type BooleanOptionalAction work in toml files."""
monkeypatch.chdir(CONFIG_DATA / "valid_toml_boolopt")
run = _Run(["test_package"])
assert not run.config.summary_quotes_same_line

# dashes in the name dont allow the dot notation to get this value
assert not run.config.__dict__["numpydoc-section-hyphen-length"]
assert run.config.__dict__["strip-whitespaces"]