espnet2.utils.yaml_no_alias_safe_dump.NoAliasSafeDumper
espnet2.utils.yaml_no_alias_safe_dump.NoAliasSafeDumper
class espnet2.utils.yaml_no_alias_safe_dump.NoAliasSafeDumper(stream, default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None, sort_keys=True)
Bases: SafeDumper
NoAliasSafeDumper is a custom YAML dumper that disables the use of anchors and
aliases in the dumped YAML data. This can help maintain a cleaner and more readable output by preventing the creation of references that can complicate the structure of the YAML document.
None
ignore_aliases(data)
Override the ignore_aliases method to always return True, disabling anchor and alias creation for the given data.
####### Examples
>>> data = {'key1': 'value1', 'key2': ['value2a', 'value2b']}
>>> yaml_str = yaml_no_alias_safe_dump(data)
>>> print(yaml_str)
key1: value1
key2:
- value2a
- value2b
NOTE
This class is a subclass of yaml.SafeDumper, which provides a safe way to dump YAML data without allowing arbitrary code execution.
ignore_aliases(data)
Disable the creation of YAML aliases for the given data.
This method is overridden to ensure that no anchors or aliases are created when dumping data to YAML. This is particularly useful when you want a clean representation of your data without the potential confusion of YAML aliases.
- Parameters:data – The data to be serialized into YAML.
- Returns: Always returns True, indicating that aliases should be ignored.
- Return type: bool
####### Examples
>>> dumper = NoAliasSafeDumper()
>>> dumper.ignore_aliases({"key": "value"})
True