Add support to load a yaml from a file
See original GitHub issueWhile ruamel.yaml
supports any kind of stream for its load
method, this is not the case for strictyaml, which currently checks the following:
if stream_type not in ("<type 'unicode'>", "<type 'str'>", "<class 'str'>"):
raise TypeError("StrictYAML can only read a string of valid YAML.")
I think strictyaml.load
should implicitly accept all the types that are supported by the underlying call to ruamel.yaml.load
.
I also strongly believe you should avoid using this kind of type comparisons and use isinstance
instead. Also consider adapting validators.py
where types are checked using ==
which is clearly a bad idea 😉
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
How can I include a YAML file inside another? - Stack Overflow
Files are loaded from classpath (Maven resources directory): /** * Custom YAML loader. It adds support to the custom !include tag which allows...
Read more >How to Load, Read, and Write YAML - Python Land
This article teaches you how to load, read, and write YAML files with PyYAML. In addition, you'll learn how to install it on...
Read more >Python YAML – Read, Write, Parse YAML - PYnative
We can add application-specific tags and assign default values to certain tags while parsing the YAML file using the load() method. The steps ......
Read more >How to use a YAML file or environment variables to populate ...
Decide where you would like to save the desired credentials or config values - in a YAML file, environment variables, or a combination...
Read more >Writing YAML files with python - Towards Data Science
Another advantage is enum support, by adding comments to a yaml file, ... Importing ruamel into python and loading the yaml file. #...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What if I don’t want to store a whole document in a string? What if I want to read a stream from the network? Why should I use an explicit
str
, not any other (lazy?) iterable? The stream api is quite common in Python, and ruamel.yaml provides support for it. It is expected that yourload
function also supports it.I believe you should either focus on (1) bringing a replacement of ruamel.yaml API with type safety support (built on top of ruamel.yaml for instance), or (2) bringing a tool that allows to validate a json (before it is loaded in ruamel) or to validate the structure returned by ruamel.yaml.load.
I don’t understand what is wrong about using
isinstance
in py2/3.This philosophy is in direct contradiction to line 2 of the zen of python: explicit is better than implicit.
I don’t personally believe that either philosophy should be used dogmatically - there is a case by case trade off to be made between both. In this case I believe there’s enough complication under the hood as it is to justify not putting even more implicit behavior in.
For objects that implement __ str __ and return YAML it isn’t a problem just do strictyaml.load(str(object)). For file handles it’s not a huge deal to just do .read().
It’s stricter.