Docker-compose no longer building image (AttributeError: cython_sources)

Important security disclaimer: I would strongly discourage anyone downgrading PyYAML to 5.3.1, as versions before 5.4 all have a known CVE — CVE-2020-14343. This issue was caused by an incompatibility of PyYAML<6.0.1 compiled under the version of Cython>=3.0, released on July 17, 2023. This has now been fixed by a new release of PyYAML, tagged …

Read more

YAML loads 5e-6 as string and not a number

The problem lies in the fact that the YAML Resolver is set up to match floats as follows: Resolver.add_implicit_resolver( u’tag:yaml.org,2002:float’, re.compile(u”’^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)? |\\.[0-9_]+(?:[eE][-+][0-9]+)? |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]* |[-+]?\\.(?:inf|Inf|INF) |\\.(?:nan|NaN|NAN))$”’, re.X), list(u’-+0123456789.’)) whereas the YAML spec specifies the regex for scientific notation as: -? [1-9] ( \. [0-9]* [1-9] )? ( e [-+] [1-9] [0-9]* )? the latter makes the …

Read more

TypeError: load() missing 1 required positional argument: ‘Loader’ in Google Colab

Now, the load() function requires parameter loader=Loader. If your YAML file contains just simple YAML (str, int, lists), try to use yaml.safe_load() instead of yaml.load(). And If you need FullLoader, you can use yaml.full_load(). Starting from pyyaml>=5.4, it doesn’t have any discovered critical vulnerabilities, pyyaml status. source: https://stackoverflow.com/a/1774043/13755823 yaml.safe_load() should always be preferred unless you …

Read more

How can I control what scalar form PyYAML uses for my data?

Falling in love with @lbt’s approach, I got this code: import yaml def str_presenter(dumper, data): if len(data.splitlines()) > 1: # check for multiline string return dumper.represent_scalar(‘tag:yaml.org,2002:str’, data, style=”|”) return dumper.represent_scalar(‘tag:yaml.org,2002:str’, data) yaml.add_representer(str, str_presenter) # to use with safe_dump: yaml.representer.SafeRepresenter.add_representer(str, str_presenter) It makes every multiline string be a block literal. I was trying to avoid the …

Read more

PyYAML dump format

Below, ruamel.yaml is used instead. ruamel.yaml is actively maintained. Unlike PyYAML, ruamel.yaml supports: YAML <= 1.2. PyYAML only supports YAML <= 1.1. This is vital, as YAML 1.2 intentionally breaks backward compatibility with YAML 1.1 in several edge cases. This would usually be a bad thing. In this case, this renders YAML 1.2 a strict …

Read more