diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index e7d2236b787..ae6bc370251 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -23,7 +23,7 @@ import re import sys import textwrap -from typing import Dict, List, Match, Optional, Pattern, Sequence, Set, Tuple +from typing import Any, Dict, List, Match, Optional, Pattern, Sequence, Set, Tuple # autogenerated by setuptools_scm from ._version import __version__ as VERSION # type: ignore # noqa: N812 @@ -301,6 +301,11 @@ def _split_lines(self, text: str, width: int) -> List[str]: return out +def _toml_to_parseconfig(toml_dict: Dict[str, Any]) -> Dict[str, Any]: + """Convert a dict read from a TOML file to the parseconfig.read_dict() format.""" + return {k: "" if v is True else v for k, v in toml_dict.items() if v is not False} + + def parse_options( args: Sequence[str], ) -> Tuple[argparse.Namespace, argparse.ArgumentParser, List[str]]: @@ -566,6 +571,8 @@ def parse_options( for toml_file in toml_files: with open(toml_file, "rb") as f: data = tomllib.load(f).get("tool", {}) + if "codespell" in data: + data["codespell"] = _toml_to_parseconfig(data["codespell"]) config.read_dict(data) # Collect which config files are going to be used