File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 2
2
This module contains the custom YAML load and dump functions and associated
3
3
loader and dumper
4
4
"""
5
+
6
+ import warnings
5
7
from collections import OrderedDict , UserString
6
8
from string import Template
7
9
@@ -16,7 +18,19 @@ class Dumper(yaml.SafeDumper):
16
18
pass
17
19
18
20
21
+ def _check_duplicate_dict_keys (loader , node ):
22
+ seen_keys = []
23
+ for key_node , _ in node .value :
24
+ key = loader .construct_scalar (key_node )
25
+ if key in seen_keys :
26
+ warnings .warn (
27
+ f"{ loader .name } : previous entry with duplicate YAML dictionary key '{ key } ' overwritten" , UserWarning
28
+ )
29
+ seen_keys .append (key )
30
+
31
+
19
32
def _dict_constructor (loader , node ):
33
+ _check_duplicate_dict_keys (loader , node )
20
34
return OrderedDict (loader .construct_pairs (node ))
21
35
22
36
You can’t perform that action at this time.
0 commit comments