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

style not preserved when modifying dict #170

Closed
virtuald opened this issue Feb 2, 2022 · 1 comment · Fixed by #173
Closed

style not preserved when modifying dict #170

virtuald opened this issue Feb 2, 2022 · 1 comment · Fixed by #173

Comments

@virtuald
Copy link

virtuald commented Feb 2, 2022

First off, thanks for this library. A style-preserving writer is a really useful and rare thing. Here's my config:

[versions]
robotpy-wpiutil             = "2022.2.1.1"
pyntcore                    = "2022.2.1.1"
robotpy-hal                 = "2022.2.1.1"
robotpy-wpimath             = "2022.2.1.2"
wpilib                      = "2022.2.1.3"
robotpy-halsim-gui          = "2022.2.1.0"
robotpy-halsim-ds-socket    = "2022.2.1.0"
robotpy-halsim-ws           = "2022.2.1.0"
robotpy-commands-v1         = "2022.2.1.1"
robotpy-commands-v2         = "2022.2.1.1"

When I run

import tomlkit

with open("cfg.toml") as fp:
    cfgdata = tomlkit.parse(fp.read())

cfgdata["versions"]["robotpy-wpimath"] = "2022.2.1.4"
print(tomlkit.dumps(cfgdata))

The output is

[versions]
robotpy-wpiutil             = "2022.2.1.1"
pyntcore                    = "2022.2.1.1"
robotpy-hal                 = "2022.2.1.1"
robotpy-wpimath = "2022.2.1.4"
wpilib                      = "2022.2.1.3"
robotpy-halsim-gui          = "2022.2.1.0"
robotpy-halsim-ds-socket    = "2022.2.1.0"
robotpy-halsim-ws           = "2022.2.1.0"
robotpy-commands-v1         = "2022.2.1.1"
robotpy-commands-v2         = "2022.2.1.1"

For now, my workaround is to directly assign the _value, and the style information is retained:

import tomlkit

with open("cfg.toml") as fp:
    cfgdata = tomlkit.parse(fp.read())

cfgdata["versions"]["robotpy-wpimath"]._value = "2022.2.1.4"
print(tomlkit.dumps(cfgdata))

Is this intended behavior, or am I missing something? From reading the quickstart, it seemed to me that just assigning the dictionary would keep style information, but that doesn't seem to be the case.

@virtuald
Copy link
Author

virtuald commented Feb 2, 2022

... actually, my workaround doesn't actually work. Oops.

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 a pull request may close this issue.

1 participant