structured_data._nillable_write   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 9
dl 0
loc 17
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A nillable_write() 0 8 2
1
"""Function for treating Python dicts sort of like Lua tables."""
2
3
import typing
4
5
_K = typing.TypeVar("_K")
6
_V = typing.TypeVar("_V")
7
8
9
def nillable_write(
10
    dct: typing.Dict[_K, _V], key: _K, value: typing.Optional[_V]
11
) -> None:
12
    """Set to the value or delete the given key in the given dict."""
13
    if value is None:
14
        dct.pop(key, typing.cast(_V, None))
15
    else:
16
        dct[key] = value
17