diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-06-25 11:01:01 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-06-25 11:01:17 +0300 |
commit | 3f282d22fb44a65cebd45632b4d28920fbad5daf (patch) | |
tree | 5b07fe1090fb87074807c57a819ff2dc071a57d8 /space_view3d_math_vis | |
parent | fcea7efd6058a6b504e7690ec9c2706546d957c1 (diff) |
Fix T66107: Error when numpy arrays are defined in math-vis add-on
Diffstat (limited to 'space_view3d_math_vis')
-rw-r--r-- | space_view3d_math_vis/utils.py | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/space_view3d_math_vis/utils.py b/space_view3d_math_vis/utils.py index 50e4daff..7910bb9c 100644 --- a/space_view3d_math_vis/utils.py +++ b/space_view3d_math_vis/utils.py @@ -95,12 +95,29 @@ def get_math_data(): variables = {} for key, var in locals.items(): - if len(key)==0 or key[0] == "_" or not var: + if len(key) == 0 or key[0] == "_": continue - if type(var) in {Matrix, Vector, Quaternion, Euler} or \ - type(var) in {tuple, list} and is_display_list(var): - variables[key] = type(var) + type_var = type(var) + + # Rules out sets/dicts. + # It's also possible the length check below is slow + # for data with underlying linked-list structure. + if not hasattr(type_var, "__getitem__"): + continue + + # Don't do a truth test on the data because this causes an error with some + # array types, see T66107. + len_fn = getattr(type_var, "__len__", None) + if len_fn is None: + continue + if len_fn(var) == 0: + continue + + if type_var in {Matrix, Vector, Quaternion, Euler} or \ + type_var in {tuple, list} and is_display_list(var): + + variables[key] = type_var return variables |