MCPcopy Index your code
hub / github.com/python/cpython / compile_keymap

Function compile_keymap

Lib/_pyrepl/keymap.py:197–213  ·  view source on GitHub ↗
(keymap, empty=b"")

Source from the content-addressed store, hash-verified

195
196
197def compile_keymap(keymap, empty=b""):
198 r = {}
199 for key, value in keymap.items():
200 if isinstance(key, bytes):
201 first = key[:1]
202 else:
203 first = key[0]
204 r.setdefault(first, {})[key[1:]] = value
205 for key, value in r.items():
206 if empty in value:
207 if len(value) != 1:
208 raise KeySpecError("key definitions for %s clash" % (value.values(),))
209 else:
210 r[key] = value[empty]
211 else:
212 r[key] = compile_keymap(value, empty)
213 return r

Callers 10

test_empty_keymapMethod · 0.90
test_single_keymapMethod · 0.90
test_nested_keymapMethod · 0.90
test_empty_valueMethod · 0.90
test_multiple_keymapsMethod · 0.90
test_non_bytes_keyMethod · 0.90
__init__Method · 0.85

Calls 4

KeySpecErrorClass · 0.85
itemsMethod · 0.45
setdefaultMethod · 0.45
valuesMethod · 0.45

Tested by 9

test_empty_keymapMethod · 0.72
test_single_keymapMethod · 0.72
test_nested_keymapMethod · 0.72
test_empty_valueMethod · 0.72
test_multiple_keymapsMethod · 0.72
test_non_bytes_keyMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…