Keymap: tweak keymap loading type checks
For full keymaps, ensure keymap items are lists to allow predictable manipulation at runtime. When calling `keymap_init_from_data` directly, allow any sequence type to allow tools to define their keymaps as tuples.
This commit is contained in:
@@ -227,7 +227,6 @@ def _kmi_props_setattr(kmi_props, attr, value):
|
||||
|
||||
|
||||
def keymap_init_from_data(km, km_items, is_modal=False):
|
||||
assert type(km_items) is list
|
||||
new_fn = getattr(km.keymap_items, "new_modal" if is_modal else "new")
|
||||
for (kmi_idname, kmi_args, kmi_data) in km_items:
|
||||
kmi = new_fn(kmi_idname, **kmi_args)
|
||||
@@ -248,7 +247,14 @@ def keyconfig_init_from_data(kc, keyconfig_data):
|
||||
# Runs at load time, keep this fast!
|
||||
for (km_name, km_args, km_content) in keyconfig_data:
|
||||
km = kc.keymaps.new(km_name, **km_args)
|
||||
keymap_init_from_data(km, km_content["items"], is_modal=km_args.get("modal", False))
|
||||
km_items = km_content["items"]
|
||||
# Check here instead of inside 'keymap_init_from_data'
|
||||
# because we want to allow both tuple & list types in that case.
|
||||
#
|
||||
# For full keymaps, ensure these are always lists to allow for extending them
|
||||
# in a generic way that doesn't have to check for the type each time.
|
||||
assert type(km_items) is list
|
||||
keymap_init_from_data(km, km_items, is_modal=km_args.get("modal", False))
|
||||
|
||||
|
||||
def keyconfig_import_from_data(name, keyconfig_data):
|
||||
|
Reference in New Issue
Block a user