-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
Function to convert everything to plain old python objects #43
Comments
As far as I can tell, this can be achieved using the |
That seems to unwrap all of the |
Apparently loading with |
The lack of an ability to easily get plain old python objects has caused me to not use tomlkit. I don't want to have to write wrapper code to convert everything. The library should make that easy. |
I have implemented the following function, which works for most of the cases. @sdispater , if you're interested I can make a PR. def tomlkit_to_popo(d):
try:
result = getattr(d, "value")
except AttributeError:
result = d
if isinstance(result, list):
result = [tomlkit_to_popo(x) for x in result]
elif isinstance(result, dict):
result = {
tomlkit_to_popo(key): tomlkit_to_popo(val) for key, val in result.items()
}
elif isinstance(result, tomlkit.items.Integer):
result = int(result)
elif isinstance(result, tomlkit.items.Float):
result = float(result)
elif isinstance(result, tomlkit.items.String):
result = str(result)
elif isinstance(result, tomlkit.items.Bool):
result = bool(result)
return result |
You can find a converter that processes TOML Kit's dates and time classes in remarshal. |
I'm working on this right now. Should I make it so that the |
So it looks like the And theres some strange stuff going on with So it seems like theres a bit of inconsistency in that aspect. I'd be happy to fix that |
It feels like .value is a good place for it, although it's not necessarily clear whether that is/ should be recursive for container types, and changing the existing functionality always has the chance of breaking workflows. Maybe something like a .unwrap(recursive=True), method would give it a clean start. Or to_native, to_builtin, to_stdlib; "popo" has been useful for discussing this issue but I'm not sure it's very commonly used in python generally. |
Would it be reasonable for me to add a warning in each call to Edit: Should I make it only show |
I think that Anyone currently using One more decision to make is whether Trivia, Whitespace etc. should have this new method at all, or whether they should have it and return some singleton which the caller needs to deal with (can't use |
As more projects incorporate PEP518, many will be aiming to keep compatibility with their existing config files as well (be they ini, yaml, json, etc.). In order to help abstract over config files of different types, it would be useful to be able to convert tomlkit objects into POPOs. One of TOML's strengths for python is that all of its constructs can deserialise to POPOs: could this be made available for tomlkit users?
The text was updated successfully, but these errors were encountered: