[Bf-blender-cvs] [3b3eac3d4bf] master: Keymap: tweak keymap loading type checks

Campbell Barton noreply at git.blender.org
Thu Mar 14 05:56:05 CET 2019


Commit: 3b3eac3d4bf1b5fea872a858c012362dbc3a151a
Author: Campbell Barton
Date:   Thu Mar 14 15:53:48 2019 +1100
Branches: master
https://developer.blender.org/rB3b3eac3d4bf1b5fea872a858c012362dbc3a151a

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.

===================================================================

M	release/scripts/modules/bl_keymap_utils/io.py

===================================================================

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):



More information about the Bf-blender-cvs mailing list