Using ruamel.yaml v0.17.20, I'm trying to load files produced with PyYAML (or written by authors for software that only uses PyYAML). These files do not have a YAML directive, but PyYAML only supports YAML 1.1, so I need to somehow inform ruamel.yaml that it should load the file with 1.1, even though there isn't a directive.
from pathlib import Path
from ruamel.yaml import YAML
yaml = YAML()
yaml.version = (1, 1)
yaml.load(Path("some/path/to/file.yml")) # file.yml exists and does not have a YAML directive
print(yaml.version) # prints None
assert yaml.version == (1, 1) # this fails!
When I try to load a file without a YAML directive, the Parser overwrites my explicitly set yaml.version with None in Parser.process_directives():
def process_directives(self):
# ...
yaml_version = None
# code that loads directives (but there aren't any in my case)
if self.loader is not None and hasattr(self.loader, 'tags'):
self.loader.version = yaml_version
# ...
https://sourceforge.net/p/ruamel-yaml/code/ci/default/tree/parser.py#l316
The load version matters for things like parsing octals and booleans.
How can I tell ruamel.yaml to use 1.1 when parsing a stream that is missing a YAML directive?