Comments (1)
It's happening because you're using "safe=True" there, which ensures that PyYAML's more robust serialization is used, and de-serialized data will be same as original, at the cost of some prettiness.
Reason why that one string is singled-out for escaping is simple - only 0.51
will be de-serialized as a number (0.51), while 0.5.1
and 0.7.1
will be interpreted as strings anyway (due to two dots in there), so no need for quotes there.
If you won't be passing safe=True, you should get desired output, but when de-serialized by any sane YAML parser, it will not match the original types, as mentioned.
Example:
% python3 -m pyaml <<< "{'y': ['0.5.1', '0.51', '0.7.1']}"
y:
- 0.5.1
- 0.51
- 0.7.1
% python3 -c 'import yaml; print(yaml.safe_load("{y: [0.5.1, 0.51, 0.7.1]}"))'
{'y': ['0.5.1', 0.51, '0.7.1']}
Note missing quotes around 0.51 in the last output, indicating that it indeed was parsed as a float object instead of string.
It's an intended behavior that "unsafe" (default) serializer may produce such quirks (though hopefully not many), with human-readability preferred over correctness.
Same thing also mentioned in #20, I believe.
from pretty-yaml.
Related Issues (20)
- Default to safe=True? HOT 10
- dump fails on numpy arrays HOT 3
- Cannot install with Python 3.6 on Windows 10 HOT 2
- Multiline String as block and quoted Strings HOT 3
- Since dict is ordered by default since 3.6, the order is lost now HOT 1
- yaml.composer.ComposerError: expected a single document in the stream HOT 1
- Deprecation warning HOT 1
- Format and write into file HOT 2
- RepresenterError: 'cannot represent an object' for custom object HOT 5
- pyaml not compatible with ruamel.yaml HOT 8
- openapi.yaml is invalid after re-formatting HOT 2
- % cannot start any token HOT 1
- Why does it sort my keys in alphabet order? HOT 2
- Although I'm using string_val_style='plain', a string value is still quoted HOT 2
- pretty-yaml creates output not readable by itself for escaped strings HOT 2
- Test regression with Python 3.11: DumpTests.test_enum HOT 2
- To ensure Python compatibility, it is recommended to avoid using the := operator in your code. HOT 1
- 23.5.9 from pypi installs empty directory HOT 6
- dump() arguments: stream vs dst HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pretty-yaml.