structured_data._nillable_write.nillable_write()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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