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

Support Decimal serialization? #288

Closed
goodboy opened this issue May 12, 2023 · 1 comment · Fixed by #296
Closed

Support Decimal serialization? #288

goodboy opened this issue May 12, 2023 · 1 comment · Fixed by #296

Comments

@goodboy
Copy link

goodboy commented May 12, 2023

Love this lib btw, it's been a huge headache trying to write a certain style of TOML with anything else; code base is also very easy to nav, so big 👍🏼

So the tomli lib has this and it'd sure be handy to have here instead of having to traverse a tree to convert everything to str first 😂

I think to start it'd be good enough to just serialize to String since presumably on parse the client code should know if it wants to cast to decimal (and obvsly TOML doesn't spec a decimal type); though i guess it wouldn't be too hard to add some logic + flag to .parser.Parser._parse_number() ?

goodboy added a commit to pikers/piker that referenced this issue May 17, 2023
We still need to get some patches landed in order to resolve:
- python-poetry/tomlkit#288
- python-poetry/tomlkit#289
- python-poetry/tomlkit#290

But, this does work for style preservation and the inline-table style we
were previously hacking into the `toml` lib in `.accounting._toml`,
which we can pretty much just drop now B)

Relates to #496 (pretty much solves it near-term i think?)
goodboy added a commit to pikers/tomlkit that referenced this issue May 25, 2023
For `decimal.Decimal` we can just encode as a `String` and leave it up
to the user how to decode the value on load. For `dict` it's quite handy
to just render any type that quacks like a `MutableMapping` to a table.

Resolves python-poetry#288 and python-poetry#289 but still needs tests!
goodboy added a commit to pikers/tomlkit that referenced this issue May 25, 2023
For `decimal.Decimal` we can just encode as a `String` and leave it up
to the user how to decode the value on load. For `dict` it's quite handy
to just render any type that quacks like a `MutableMapping` to a table.

Resolves python-poetry#288 and python-poetry#289 but still needs tests!
@goodboy
Copy link
Author

goodboy commented Jun 27, 2023

As per discussion in #294 it makes more sense to just expect users to define a custom encoder since there's no type support in the TOML spec for Decimal:
#294 (comment)

Those looking for a solution can defer to @frostming's comment linked above.

@goodboy goodboy closed this as completed Jun 27, 2023
@frostming frostming linked a pull request Jun 28, 2023 that will close this issue
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