Skip to content

Commit

Permalink
Merge pull request #58 from jonathangreen/bugfix/typeerror-with-pypro…
Browse files Browse the repository at this point in the history
…ject

Fix TypeError when using Pyproject.toml
  • Loading branch information
pappasam committed May 8, 2023
2 parents 2af9ed4 + d8b3b8d commit eb13667
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 15 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,21 @@ def test_load_config_overrides(toml, expected):
open_mock = mock.mock_open(read_data=toml)
with mock.patch("toml_sort.cli.open", open_mock):
section = cli.load_pyproject()
assert expected == cli.parse_config_overrides(section)
assert isinstance(section, dict)
parsed = cli.parse_config_overrides(section)
assert expected == parsed
# Make sure we are returning normal python types rather
# than TOMLKit types.
for key, value in parsed.items():
assert type(key) == str # pylint: disable=unidiomatic-typecheck
assert (
type(value) # pylint: disable=unidiomatic-typecheck
== SortOverrideConfiguration
)
assert (
type(value.first) # pylint: disable=unidiomatic-typecheck
== list
)


@pytest.mark.parametrize(
Expand Down
7 changes: 4 additions & 3 deletions toml_sort/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ def parse_config_overrides(
"""Parse the tool.tomlsort.overrides section of the config."""
fields = dataclasses.fields(SortOverrideConfiguration)
settings_definition = {field.name: field.type for field in fields}
override_settings = dict(
tomlsort_section.get("overrides", tomlkit.document())
)
override_settings = tomlsort_section.get(
"overrides", tomlkit.document()
).unwrap()

overrides = {}
for path, settings in override_settings.items():
if not settings.keys() <= settings_definition.keys():
Expand Down

0 comments on commit eb13667

Please sign in to comment.