garcia / simfile

A modern simfile parsing & editing library for Python 3
MIT License
62 stars 7 forks source link

`AttributeError` during simfile serialization if any value is `None` #40

Closed garcia closed 1 year ago

garcia commented 1 year ago

msdparser returns a value of None when a parameter has no colon separator (e.g. #KEY;). This deserializes into a simfile object correctly, but attempting to serialize it back to a string throws an AttributeError:

File "/lib/python3.10/site-packages/simfile/_private/serializable.py", line 19, in __str__
self.serialize(serialized)
File "/lib/python3.10/site-packages/simfile/base.py", line 191, in serialize
file.write(f"{param}\n")
File "/lib/python3.10/site-packages/msdparser/parameter.py", line 87, in __str__
self.serialize(output, escapes=escapes)
File "/lib/python3.10/site-packages/msdparser/parameter.py", line 80, in serialize
file.write(MSDParameter.serialize_component(component, escapes=escapes))
File "/lib/python3.10/site-packages/msdparser/parameter.py", line 57, in serialize_component
return reduce(
File "/lib/python3.10/site-packages/msdparser/parameter.py", line 58, in <lambda>
lambda key, esc: key.replace(esc, f"\\{esc}"),
AttributeError: 'NoneType' object has no attribute 'replace'
garcia commented 1 year ago

Duplicate of #33