Commit 2b5b629b authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[utils] Implement error_on_duplicate_key_hook

This hook will be used when loading JSON data to ensure
that if a key is duplicated, the system will error.
parent 937fd876
......@@ -401,6 +401,26 @@ class NumpyJSONEncoder(simplejson.JSONEncoder):
# ----------------------------------------------------------
def error_on_duplicate_key_hook(pairs):
"""JSON loader hook that will error out if several same keys are found
Returns an OrderedDict if everything goes well
"""
dct = collections.OrderedDict()
for key, value in pairs:
if key in dct:
raise RuntimeError(
"Invalid file content\n{} found several times".format(key)
)
dct[key] = value
return dct
# ----------------------------------------------------------
def has_argument(method, argument):
try:
from inspect import signature
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment