j2y: use a slightly smarter heuristic for disabling flow style in the output YAML

This commit is contained in:
Danielle McLean 2018-04-09 08:36:38 +10:00
parent 6ee96690b6
commit a935bfe173
Signed by: 00dani
GPG key ID: 8EB789DDF3ABD240

View file

@ -11,7 +11,7 @@ def dict_representer(dumper, d):
node = dumper.represent_dict(d) node = dumper.represent_dict(d)
# Don't use YAML flow style for large dicts, because the flow style output # Don't use YAML flow style for large dicts, because the flow style output
# only really looks good with a very small number of keys. # only really looks good with a very small number of keys.
if node.flow_style and len(d) > 5: if len(d) > 5 or sum(len(v) for v in d.values()) > 30:
node.flow_style = False node.flow_style = False
return node return node
Dumper.add_representer(dict, dict_representer) Dumper.add_representer(dict, dict_representer)