-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
ValueError: Invalid type <class 'NoneType'> #240
Comments
We also found that, when using the access pattern to directly serialize to a file, with open("testdrive.toml", "w") as config_file:
tomlkit.dump(data, config_file)
|
@amotl You are suggesting to ignore the From toml specifications "Unspecified values are invalid.", but comments are. For instance, this dictionary: a = 1
# b = None As a workaround, I strip the dictionary from empty values: def stripper(data):
"""
Workaround for:
https://github.com/sdispater/tomlkit/issues/240
"""
new_data = {}
for k, v in data.items():
if isinstance(v, dict):
v = stripper(v)
if v not in (u"", None, {}):
new_data[k] = v
return new_data |
This comment was marked as resolved.
This comment was marked as resolved.
Dear @amotl I have updated my previous reply to make it clearer. Sorry for this initial version that wasn't clear at all. |
None type isn't supported by TOML spec and we are not going to do things beyond that. So no special handling, just as other parsers do. Closing it now |
Dear @sdispater and @frostming,
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).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 oftomli-w
at hukkin/tomli-w#39.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: