You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a configuration file that I read and write exclusively with pyyaml. As various state changes in the overall system, keys are added or removed, or their content modified; this is always by reading the file with pyyaml, tweaking the Python dictionary, and writing it back with pyyaml.
The structure defined is a dictionary with short keys. Often the keys consist entirely of digits, but sometimes they contain letters, or are even exclusively letters. Usually the number-like names have one or more leading zeros.
At first brush, it seemed like perhaps keys that might be interpreted as numbers were quoted, but that is only sometimes true. For some other examples, I thought that there was a difference in whether there were an even versus odd number of leading zeros, but that is violated in the example shown. E.g. sometimes an all-digits code with one leading zero is quoted, sometimes not. Same with two, three, or four leading zeros.
We also use another configuration file that is similar, but contains different information about a subset of the keys in the mentioned file. It appears that the decision to quote or not quote is consistent per key, but the latter file only contains a fairly small subset of the keys in the exhibited one (what's shown is just a few of the keys that illustrate this ticket).
This behavior isn't really a bug since what is produced is valid YAML that can easily be read by pyyaml. It's more like a quirk (at least in the uses I've had so far). In what I've seen, only keys that contain only digits are ever quoted.
[...]
'00015':
preferred_source: Ada
00021LA:
preferred_source: Ada
'00026':
preferred_source: Ada
00048:
preferred_source: Ada
'01107':
preferred_source: Ada
01199NE:
preferred_source: Ada
01948:
preferred_source: Ada
X298:
preferred_source: Ada
[...]
The text was updated successfully, but these errors were encountered:
strings need to be quoted if they resolve to something special, e.g. a number or a boolean.
Decimal numbers can't have zeroes at the beginning, octal numbers must. 00015 would be a (octal) number because it starts with a zero, 00021LA wouldn't be a number. 01948 looks like a number, but it has a 9, which can't be in an octal, so it doesn't need to be quoted.
For more details please check the pinned issue with lots of duplicate issues linked: #486
Feel free to try out my https://pypi.org/project/yamlcore/ package which works just on top of PyYAML and supports the YAML 1.2 Core schema.
You will get a much more reasonably looking result here.
I have a configuration file that I read and write exclusively with pyyaml. As various state changes in the overall system, keys are added or removed, or their content modified; this is always by reading the file with pyyaml, tweaking the Python dictionary, and writing it back with pyyaml.
The structure defined is a dictionary with short keys. Often the keys consist entirely of digits, but sometimes they contain letters, or are even exclusively letters. Usually the number-like names have one or more leading zeros.
At first brush, it seemed like perhaps keys that might be interpreted as numbers were quoted, but that is only sometimes true. For some other examples, I thought that there was a difference in whether there were an even versus odd number of leading zeros, but that is violated in the example shown. E.g. sometimes an all-digits code with one leading zero is quoted, sometimes not. Same with two, three, or four leading zeros.
We also use another configuration file that is similar, but contains different information about a subset of the keys in the mentioned file. It appears that the decision to quote or not quote is consistent per key, but the latter file only contains a fairly small subset of the keys in the exhibited one (what's shown is just a few of the keys that illustrate this ticket).
This behavior isn't really a bug since what is produced is valid YAML that can easily be read by pyyaml. It's more like a quirk (at least in the uses I've had so far). In what I've seen, only keys that contain only digits are ever quoted.
The text was updated successfully, but these errors were encountered: