Skip to content

Commit

Permalink
Modify dicts read from TOML config files
Browse files Browse the repository at this point in the history
Remove booleans to match dicts read from INI files, as
parseconfig.read_dict() expects a dict read from an INI
file.
  • Loading branch information
DimitriPapadopoulos committed Aug 31, 2023
1 parent 66f8211 commit 2121d60
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]]:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2121d60

Please sign in to comment.