Passed
Pull Request — master (#536)
by Konstantin
01:40
created

ocrd_utils.introspect   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 13
dl 0
loc 18
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A membername() 0 3 1
A set_json_key_value_overrides() 0 8 3
1
"""
2
Utility functions to simplify access to data structures.
3
"""
4
import json
5
6
def membername(class_, val):
7
    """Convert a member variable/constant into a member name string."""
8
    return next((k for k, v in class_.__dict__.items() if v == val), str(val))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable k does not seem to be defined.
Loading history...
9
10
def set_json_key_value_overrides(obj, *kvpairs):
11
    for kv in kvpairs:
12
        k, v = kv
13
        try:
14
            obj[k] = json.loads(v)
15
        except json.decoder.JSONDecodeError:
16
            obj[k] = v
17
    return obj
18