-
Notifications
You must be signed in to change notification settings - Fork 14
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
TypeError: Object of type <class 'NoneType'> is not TOML serializable #39
Comments
We also found that, when using the access pattern to directly serialize to a file, with open("testdrive.toml", "wb") as config_file:
tomli_w.dump(data, config_file)
|
Hey there, thanks for the issue! I think it's better to be strict than graceful when non serializable objects are found. If a consumer of Tomli-W needs to ignore def remove_nones(d):
if isinstance(d, dict):
return {k: remove_nones(v) for k, v in d.items() if v is not None}
return d
def write_toml_ignoring_none(d):
return tomli_w.dumps(remove_nones(d)) The function |
Dear Taneli, thank you very much for taking the time to respond to my request. I think it is fine to defer ignoring NULL values to userspace. However, you may want to revisit my comment at #39 (comment). I think it indicates that it may happen that With kind regards, |
Dear Taneli,
thanks a stack for conceiving and maintaining this excellent library. We just wanted to let you know about an issue we just discovered when serializing
NoneType
values [1]. We are aware that TOML does not know about any kinds of NULL values (toml-lang/toml#921).Differently than #34, this issue is merely a proposal to handle
NoneType
values gracefully by just ignoring them on serialization. Thetoml
package does just that [2]. We have exercised the situation with all oftoml
,tomlkit
, andtomli-w
on behalf of a unit test at [3] and also reported the same issue to the author oftomlkit
at python-poetry/tomlkit#240.With kind regards,
Andreas.
[1] isarengineering/SecPi#25
[2] isarengineering/SecPi#27
[3] https://gist.github.com/amotl/4d8bc928d781a5d0fbc7f404396f8417
The text was updated successfully, but these errors were encountered: