-
Notifications
You must be signed in to change notification settings - Fork 518
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
on and off are incorrectly interpreted when they are keys #52
Comments
It doesn't seem to follow the YAML spec (at least not the YAML 1.1 boolean spec) consistently in this regard:
|
|
@jason-s these aliases for booleans are reserved YAML keywords. This counts for keys, too, and other implementation also interpret them as booleans. If you want the string value, you have to wrap them in quotation marks. >>> import yaml
>>> yaml.safe_load("""
... "no": test
... """)
{'no': 'test'}
>>> yaml.safe_load("""
... no: test
... """)
{False: 'test'} However, the handling of y/n indeed seems to be inconsistent. |
@mjrk Even then, why would anyone want their YAML library to automatically change a key name? That doesn't make any sense to me. I understand it for values, but not keys. e: I don't see On or Off as keywords in the spec: https://yaml.org/spec/1.2/spec.html#id2803629 |
PyYAML currently only implements YAML 1.1: |
If a language like Python supports other types than strings as dictionary keys, like booleans or None, why not?
YAML makes no difference between keys and values in this regard. |
@perlpunk Touche. I personally wouldn't want my keys being transformed like that, but it makes sense that some might. I didn't realize this library only supported 1.1 and that explains my confusion. Seems like there isn't an issue here and this could be closed? |
@wirecat it's also trivial to swap in a custom resolver to your own Loader composition to alter or remove that behavior any way you'd like: https://github.com/yaml/pyyaml/blob/master/lib3/yaml/resolver.py The lack of support for |
on
andoff
are interpreted asTrue
orFalse
when used as values. But they are also interpreted this way as keys:The text was updated successfully, but these errors were encountered: