Total Complexity | 2 |
Total Lines | 17 |
Duplicated Lines | 0 % |
Changes | 0 |
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 |