Skip to content

sort_keys does not (always?) work #466

@lehmannro

Description

@lehmannro

dumps(sort_keys) does not seem to work for parsed TOML documents:

>>> tomlkit.dumps(tomlkit.loads('zzz = 1\naaa = "foo"'), sort_keys=True)
'zzz = 1\naaa = "foo"'

It works fine on regular objects, as far as I can tell:

>>> tomlkit.dumps({'zzz': 1, 'aaa': "foo"}, sort_keys=True)
'aaa = "foo"\nzzz = 1\n'

It does work when I manually apply the item(_sort_keys) wrapping done in the API:

>>> tomlkit.dumps(tomlkit.item(tomlkit.loads('zzz = 1\naaa = "foo"'), _sort_keys=True))
'aaa = "foo"\nzzz = 1\n'

I believe it's because the condition doesn't trigger since tomlkit.loads returns a TOMLDocument:

>>> x = tomlkit.loads('zzz = 1\naaa = "foo"')
>>> type(x)
<class 'tomlkit.toml_document.TOMLDocument'>
>>> isinstance(x, tomlkit.container.Container)
True

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions