Skip to content

The new formatter strips trailing zeroes from exponents, which are required for YAML 1.1 floats. #1237

@Reiff

Description

@Reiff

Summary

tl;dr the fix is to set "yaml.yamlVersion": "1.1" but this was not previously necessary and may impact a large number of python + YAML users.

The current extension's YAML formatter will replace 1.0e+4 with 1e+4.

In YAML 1.1, 1e+4 is not a valid float.
In YAML 1.2, it is.

The -- to my knowledge -- standard and widely-used interface between python and YAML, PyYAML, is still on YAML 1.1
As a result, exponents are interpreted as strings if they lack a .0

>>> import yaml
>>> yaml.safe_load("1.0e+4") 
10000.0
>>> yaml.safe_load("1e+4")  
'1e+4'

Adding more details to the formatter changelog entry ("The new formatter may perform breaking changes if yaml.yamlVersion is not set correctly, such as 1.0e+4 -> 1e+4 which are equivalent in YAML 1.2 but not YAML 1.1.") would help limit the fallout.

(PyYAML does not look likely to fix it on their side anytime soon yaml/pyyaml#173)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions