Cleanup: remove redundant dynamic tool expansion

The tools passed to _tools_flatten, _tools_flatten_with_tool_index
already have dynamic tool items expanded, so there is no need to check
for callable tool items.
This commit is contained in:
Campbell Barton
2019-12-16 15:40:20 +11:00
parent 165afb3ad0
commit 85f8690555

View File

@@ -218,49 +218,27 @@ class ToolSelectPanelHelper:
@staticmethod
def _tools_flatten(tools):
"""
Flattens, skips None and calls generators.
"""
for item in tools:
if item is None:
yield None
elif type(item) is tuple:
for sub_item in item:
if sub_item is None:
yield None
elif _item_is_fn(sub_item):
yield from sub_item(context)
else:
yield sub_item
if type(item) is tuple:
yield from item
else:
if _item_is_fn(item):
yield from item(context)
else:
yield item
# May be None.
yield item
@staticmethod
def _tools_flatten_with_tool_index(tools):
for item in tools:
if item is None:
yield None, -1
elif type(item) is tuple:
if type(item) is tuple:
i = 0
for sub_item in item:
if sub_item is None:
yield None, -1
elif _item_is_fn(sub_item):
for item_dyn in sub_item(context):
yield item_dyn, i
i += 1
else:
yield sub_item, i
i += 1
else:
if _item_is_fn(item):
for item_dyn in item(context):
yield item_dyn, -1
else:
yield item, -1
# May be None.
yield item, -1
@classmethod
def _tool_get_active(cls, context, space_type, mode, with_icon=False):