Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/pandas/compat/chainmap.py
7826 views
1
from typing import (
2
ChainMap,
3
TypeVar,
4
)
5
6
_KT = TypeVar("_KT")
7
_VT = TypeVar("_VT")
8
9
10
class DeepChainMap(ChainMap[_KT, _VT]):
11
"""
12
Variant of ChainMap that allows direct updates to inner scopes.
13
14
Only works when all passed mapping are mutable.
15
"""
16
17
def __setitem__(self, key: _KT, value: _VT) -> None:
18
for mapping in self.maps:
19
if key in mapping:
20
mapping[key] = value
21
return
22
self.maps[0][key] = value
23
24
def __delitem__(self, key: _KT) -> None:
25
"""
26
Raises
27
------
28
KeyError
29
If `key` doesn't exist.
30
"""
31
for mapping in self.maps:
32
if key in mapping:
33
del mapping[key]
34
return
35
raise KeyError(key)
36
37