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

Would it make sense to add set to ARRAY_TYPES? #30

Closed
oittaa opened this issue Dec 8, 2021 · 1 comment
Closed

Would it make sense to add set to ARRAY_TYPES? #30

oittaa opened this issue Dec 8, 2021 · 1 comment

Comments

@oittaa
Copy link

oittaa commented Dec 8, 2021

What do you think? For example people might have a list and then cast it as a set to remove duplicates.

tomli_w/_writer.py

ARRAY_TYPES = (list, set, tuple)

tests/test_types.py

def test_set():
    obj = {"test-set": {1, 2, 3}}
    assert (
        tomli_w.dumps(obj)
        == """\
test-set = [
    1,
    2,
    3,
]
"""
    )
@hukkin
Copy link
Owner

hukkin commented Dec 8, 2021

I think I'd prefer not doing this.

list and tuple are intuitive to me because they are ordered, so are TOML arrays. A set is unordered. E.g. in your test case there's no way of guaranteeing that the order is what you have in the expected TOML string.

E.g. json.dumps from the standard library also errors on sets.

@hukkin hukkin closed this as completed Dec 8, 2021
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

No branches or pull requests

2 participants