[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56426] trunk/blender/release/scripts/ modules/console/complete_namespace.py: fix for exception in console auto-completing an object with __getitem__ but no __len__ (BMEdge).

Campbell Barton ideasman42 at gmail.com
Wed May 1 01:01:13 CEST 2013


Revision: 56426
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56426
Author:   campbellbarton
Date:     2013-04-30 23:01:12 +0000 (Tue, 30 Apr 2013)
Log Message:
-----------
fix for exception in console auto-completing an object with __getitem__ but no __len__ (BMEdge).

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/console/complete_namespace.py

Modified: trunk/blender/release/scripts/modules/console/complete_namespace.py
===================================================================
--- trunk/blender/release/scripts/modules/console/complete_namespace.py	2013-04-30 22:46:41 UTC (rev 56425)
+++ trunk/blender/release/scripts/modules/console/complete_namespace.py	2013-04-30 23:01:12 UTC (rev 56426)
@@ -96,12 +96,22 @@
     if not hasattr(obj, '__getitem__'):
         # obj is not a list or dictionary
         return []
-    if is_dict(obj):
+
+    obj_is_dict = is_dict(obj)
+
+    # rare objects have a __getitem__ but no __len__ (eg. BMEdge)
+    if not obj_is_dict:
+        try:
+            obj_len = len(obj)
+        except TypeError:
+            return []
+
+    if obj_is_dict:
         # dictionary type
         matches = ['%s[%r]' % (base, key) for key in sorted(obj.keys())]
     else:
-        # list type
-        matches = ['%s[%d]' % (base, idx) for idx in range(len(obj))]
+        # list type, 
+        matches = ['%s[%d]' % (base, idx) for idx in range(obj_len)]
     if word != base:
         matches = [match for match in matches if match.startswith(word)]
     return matches




More information about the Bf-blender-cvs mailing list