loader.flatten_mapping(node)
nodes = loader.construct_pairs(node)
dups = [k for k, v in Counter(k for k, _ in nodes).items() if v > 1]
if dups:
raise yaml.YAMLError("ERROR: duplicate keys: {}".format(dups))
return OrderedDict(nodes)
yaml.SafeLoader.add_constructor("!include", _include_yaml)
After Change
for (key, _), (node, _) in zip(nodes, node.value):
line = getattr(node, "__line__", "unknown")
if key in seen:
fname = getattr(loader.stream, "name", "")
raise yaml.YAMLError("ERROR: duplicate key: \"{}\""
" in {} line {} and {}"
.format(key, fname, seen[key], line))
seen[key] = line