Skip to content
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

exclamation marks on null list items #47

Open
fargiolas opened this issue Feb 25, 2021 · 1 comment
Open

exclamation marks on null list items #47

fargiolas opened this issue Feb 25, 2021 · 1 comment

Comments

@fargiolas
Copy link

fargiolas commented Feb 25, 2021

Hi I'm trying to edit a yaml config file without messing with the original formatting. I'm loading it with

config, yaml_indent, yaml_block_seq_indent = ruamel.yaml.util.load_yaml_guess_indent(fp, preserve_quotes=True)

and dumping it with:

ruamel.yaml.round_trip_dump(config, fp, indent=yaml_indent, block_seq_indent=yaml_block_seq_indent)

everything looks fine except I a few lists with null elements which look like

list: ["a", "b", null, null, null]

in the original file but become in the edited one:

list: ["a", "b", !!null '', !!null'', !!null'']

Is this expected? any way to avoid it? I'd like to keep the file easy to read and modify by a human.

@fargiolas
Copy link
Author

fargiolas commented Feb 26, 2021

I was able to fix this forcing a representer for type(None)

    def represent_none(self, data):
        return self.represent_scalar('tag:yaml.org,2002:null', u'null')
    yaml.representer.add_representer(type(None), represent_none)

What's weird is that the very same representer is added in lib/ruyaml/representer.py to bouth round trip and safe dumper, so AFAIK it should work as expected without manually forcing it. Am I missing anything?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant