diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-14 07:53:48 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-14 07:53:48 +0300 |
commit | 3b3eac3d4bf1b5fea872a858c012362dbc3a151a (patch) | |
tree | b326faf6f0686b7b4042d6debeb50cf912f24b24 | |
parent | 0bd45a2d51cf9c6a1c4b1adef254373286507414 (diff) |
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.
-rw-r--r-- | release/scripts/modules/bl_keymap_utils/io.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/release/scripts/modules/bl_keymap_utils/io.py b/release/scripts/modules/bl_keymap_utils/io.py index ee08a2d7fb0..531c620348d 100644 --- a/release/scripts/modules/bl_keymap_utils/io.py +++ b/release/scripts/modules/bl_keymap_utils/io.py @@ -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): |