to_yaml for Box and BoxList: with comments and the ruamel round trip dumper, write them out, otherwise dump `plain` exactly as before.
(obj, plain, filename=None, encoding: str = "utf-8", errors: str = "strict", **yaml_kwargs)
| 331 | |
| 332 | |
| 333 | def dump_yaml(obj, plain, filename=None, encoding: str = "utf-8", errors: str = "strict", **yaml_kwargs): |
| 334 | """ |
| 335 | to_yaml for Box and BoxList: with comments and the ruamel round trip dumper, write them out, |
| 336 | otherwise dump `plain` exactly as before. |
| 337 | """ |
| 338 | from box import converters |
| 339 | |
| 340 | use_comments = converters.ruamel_available and yaml_kwargs.get("ruamel_typ", "rt") == "rt" and has_comments(obj) |
| 341 | if not use_comments: |
| 342 | return converters._to_yaml(plain, filename=filename, encoding=encoding, errors=errors, **yaml_kwargs) |
| 343 | body = converters._to_yaml(commented_tree(obj, plain), encoding=encoding, errors=errors, **yaml_kwargs) |
| 344 | # Document comments are written as text: ruamel drops a blank line after a start comment |
| 345 | text = _document_lines(obj, "start") + body + _document_lines(obj, "end") |
| 346 | if not filename: |
| 347 | return text |
| 348 | converters._exists(filename, create=True) |
| 349 | with open(filename, "w", encoding=encoding, errors=errors) as f: |
| 350 | f.write(text) |
| 351 | return None |
nothing calls this directly
no test coverage detected