diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-05-01 03:01:12 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-05-01 03:01:12 +0400 |
commit | 56e6c14e1e823da60de3bf8b21eef54b5e7d5b66 (patch) | |
tree | d19c1992a52e54152ab49608ab4d7a69b1b03eea /release/scripts/modules | |
parent | 6af6c96e8541c2138f5784d8b2258437d048d095 (diff) |
fix for exception in console auto-completing an object with __getitem__ but no __len__ (BMEdge).
Diffstat (limited to 'release/scripts/modules')
-rw-r--r-- | release/scripts/modules/console/complete_namespace.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/release/scripts/modules/console/complete_namespace.py b/release/scripts/modules/console/complete_namespace.py index d787fed0967..31e4f3cf225 100644 --- a/release/scripts/modules/console/complete_namespace.py +++ b/release/scripts/modules/console/complete_namespace.py @@ -96,12 +96,22 @@ def complete_indices(word, namespace, obj=None, base=None): 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 |