MCPcopy Create free account
hub / github.com/bpython/bpython / KeyMap

Class KeyMap

bpython/keys.py:29–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27
28
29class KeyMap(Generic[T]):
30 def __init__(self, default: T) -> None:
31 self.map: dict[str, T] = {}
32 self.default = default
33
34 def __getitem__(self, key: str) -> T:
35 if not key:
36 # Unbound key
37 return self.default
38 elif key in self.map:
39 return self.map[key]
40 else:
41 raise KeyError(
42 f"Configured keymap ({key}) does not exist in bpython.keys"
43 )
44
45 def __delitem__(self, key: str) -> None:
46 del self.map[key]
47
48 def __setitem__(self, key: str, value: T) -> None:
49 self.map[key] = value
50
51
52cli_key_dispatch: KeyMap[tuple[str, ...]] = KeyMap(tuple())

Callers 1

keys.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected