hnluo
2023-04-27 c5992ca03ea6d6c7b78e5c1d481a612d0f91ac21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import yaml
 
 
class NoAliasSafeDumper(yaml.SafeDumper):
    # Disable anchor/alias in yaml because looks ugly
    def ignore_aliases(self, data):
        return True
 
 
def yaml_no_alias_safe_dump(data, stream=None, **kwargs):
    """Safe-dump in yaml with no anchor/alias"""
    return yaml.dump(
        data, stream, allow_unicode=True, Dumper=NoAliasSafeDumper, **kwargs
    )