Bug: StrictYaml cannot serialize `None` (null value)
See original GitHub issueTyping the following into the python interpreter
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import strictyaml
>>> yaml = strictyaml.as_document({'a':None})
results in
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Temp\3\venv3\lib\site-packages\strictyaml\parser.py", line 258, in as_document
return schema(YAMLChunk(schema.to_yaml(data), label=label))
File "D:\Temp\3\venv3\lib\site-packages\strictyaml\any_validator.py", line 45, in to_yaml
return schema_from_data(data).to_yaml(data)
File "D:\Temp\3\venv3\lib\site-packages\strictyaml\compound.py", line 197, in to_yaml
for key, value in data.items()
File "D:\Temp\3\venv3\lib\site-packages\strictyaml\compound.py", line 200, in <listcomp>
and value != self._defaults[key]
File "D:\Temp\3\venv3\lib\site-packages\strictyaml\scalar.py", line 148, in to_yaml
raise YAMLSerializationError("'{}' is not a string".format(data))
strictyaml.exceptions.YAMLSerializationError: 'None' is not a string
This appears to be a bug. (If it is not a bug, this gaping feature-hole is not documented anywhere.)
Issue Analytics
- State:
- Created 4 years ago
- Comments:20 (7 by maintainers)
Top Results From Across the Web
Changelog - HitchDev
BUGFIX : Fix for bug caused by revalidation with Optional default values. ... BUGFIX : Fixed the way serialization of empty lists, dicts,...
Read more >cannot serialize None (type NoneType) in ElementTree ...
I was wondering if there is a way to avoid writing the attribute at all if the value of the attribute is None....
Read more >The Norway Problem | Hacker News
I mean if the value is imported as a decimal, then a sort by that field will sort as decimal. This might not...
Read more >YAML: The Missing Battery in Python
You'll also serialize Python objects and create a YAML syntax ... state the lack of a value, but you can also leave the...
Read more >why StrictYAML refuses to do implicit typing and so should you
It's not "the Norway Problem" it's "the YAML Problem". ... takes yes/no, true/false, and I think on/off as boolean values while encouraging ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can add a NoneValidator which will accept values other than empty (defaulting to null) if that helps?
On Wed, 22 Apr 2020, 14:25 ArneBachmannDLR, notifications@github.com wrote:
I think it would be useful to define a value to be optionally None (YAML’s
null
). The problem is thatNone
is already taken in Python, so thatNone()
is not available, therefore I went withNone_()
. An alternative might beNoneOr(Type())
orNullable(Type)
.