Description
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
[...]