1. Kirill Simonov
  2. pyyaml
Issue #21 new

Python implementation of safe_dump converts string of an int into an int

Timothy Corbett-Clark
created an issue

So a string containing something which looks like an integer will be dumped in to yaml which is an integer. Hence round tripping is not true. yaml.dump seems to work correctly by preserving the escaping quotes:

assert yaml.safe_load(yaml.safe_dump('2')) == 2
assert yaml.load(yaml.dump('2')) == '2'

Comments (4)

  1. Timothy Corbett-Clark reporter

    The CSafeDumper also works as I would expect, so perhaps this is limited to the Python implementation::

    assert yaml.safe_load(yaml.dump('2', None, Dumper=yaml.CSafeDumper)) == '2'
  2. Log in to comment