Deserializing to native data structures typically results in comment loss, and you cannot really write comments programmatically. (In most implementations, actually. You can indeed preserve comments in Python's ruamel.yaml.)
Solution? I suggest a half-deserialized format, XML tree (with comments), then traverse via XPath, only to continue to native data structures, if asked to.