Passed
Push — master ( 903ac6...71efa5 )
by Konstantin
02:59 queued 13s
created

ocrd_utils.introspect.membername()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nop 2
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