-
Notifications
You must be signed in to change notification settings - Fork 551
Open
Description
When processing a yaml document that has a string value that could be interpreted as a number in scientific form, the dumped value is not quoted, causing problems when composing multiple documents and rendering the outcome as such
Example:
import yaml
document = """
list:
- code: '6E01'
- code: '1234'
- code: ABCD
"""
loaded = yaml.load(document, yaml.BaseLoader)
print(loaded)
print(yaml.dump(loaded, default_flow_style=False))
print(yaml.dump(loaded, default_flow_style=True))The above code generates the following output
{'list': [{'code': '6E01'}, {'code': '1234'}, {'code': 'ABCD'}]}
list:
- code: 6E01
- code: '1234'
- code: ABCD
{list: [{code: 6E01}, {code: '1234'}, {code: ABCD}]}
Which is incorrect, since now the first code in the list is interpreted as a number (60.0) instead of the string 6E01.
I am expecting this to be
{'list': [{'code': '6E01'}, {'code': '1234'}, {'code': 'ABCD'}]}
list:
- code: '6E01' << quoted
- code: '1234'
- code: ABCD
{list: [{code: '6E01'}, {code: '1234'}, {code: ABCD}]} << quoted '6E01'
Metadata
Metadata
Assignees
Labels
No labels