pyyaml
pyyaml copied to clipboard
Octal numbers processed as strings
I expect
- octal numbers processed as integers
yaml.safe_load('a: 0o1') == {"a": 1}
instead
yaml.safe_load('a: 0o1') == {"a": "0o1"}
PyYAML only implements YAML 1.1 so far.
In YAML 1.1, octal numbers just have a leading zero, e.g. 0755
.
In YAML 1.2 Core Schema, they start with 0o
, e.g. 0o755
.
See https://perlpunk.github.io/yaml-test-schema/schemas.html
There are plans to support YAML 1.2 in PyYAML, and the first steps have been made. See https://github.com/yaml/pyyaml/issues/486 There are open questions about the API, the technical part is practically done.
Ok, but shouldn't the following raise?
In [12]: yaml.safe_load("""
...: %YAML 1.2
...: ---
...: a: 0o12
...: """)
Out[12]: {'a': '0o12'}
it should, but currently it allows many values for the directive without changing behaviour or reising.