Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeError when using Pyproject.toml #58

Merged

Conversation

jonathangreen
Copy link
Contributor

Found this error when using the first override in a pyproject.toml file. It was happening because tomlkit wrappers were making it into the configuration, causing the dataclass not to be serialize to a dict.

Traceback (most recent call last):
  File "/bin/toml-sort", line 8, in <module>
    sys.exit(cli())
  File "/toml_sort/cli.py", line 413, in cli
    sorted_toml = TomlSort(
  File "/toml_sort/tomlsort.py", line 810, in sorted
    sorted_toml = self.toml_doc_sorted(toml_doc)
  File "/toml_sort/tomlsort.py", line 796, in toml_doc_sorted
    self.toml_elements_sorted(item, sorted_document),
  File "/toml_sort/tomlsort.py", line 611, in toml_elements_sorted
    self.toml_elements_sorted(item, previous_item),
  File "/toml_sort/tomlsort.py", line 611, in toml_elements_sorted
    self.toml_elements_sorted(item, previous_item),
  File "/toml_sort/tomlsort.py", line 604, in toml_elements_sorted
    for item in self.sorted_children_table(
  File "/toml_sort/tomlsort.py", line 542, in sorted_children_table
    sort_config = self.sort_config(parent_keys)
  File "/toml_sort/tomlsort.py", line 336, in sort_config
    override_config = asdict(override)
  File "dataclasses.py", line 1075, in asdict
    return _asdict_inner(obj, dict_factory)
  File "dataclasses.py", line 1082, in _asdict_inner
    value = _asdict_inner(getattr(obj, f.name), dict_factory)
  File "dataclasses.py", line 1110, in _asdict_inner
    return type(obj)(_asdict_inner(v, dict_factory) for v in obj)
TypeError: __init__() missing 1 required positional argument: 'trivia'

Added a test to check that the types we get out of the config are plain old python objects and fixed this issue.

@jonathangreen
Copy link
Contributor Author

This is what I had in my pyproject.toml that was triggering the error for me:

[tool.tomlsort.overrides]
"tool.poetry.dependencies".first = ["python"]

@pappasam
Copy link
Owner

pappasam commented May 8, 2023

🚀

@pappasam pappasam merged commit eb13667 into pappasam:main May 8, 2023
@jonathangreen jonathangreen deleted the bugfix/typeerror-with-pyproject branch May 9, 2023 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants