Fix T44822: python enums' itemf callback did not handle 'NULL' context case.
Enum's itemf callback can be called without context in some cases (UI, doc generation...). Python's enum properties did not handle this at all - it's kind of odd this did not cause more trouble and wasn't notice earlier... Probably dynamic enums using context are not much used in py code. Note about nodes: those are heavy users of dynamic enum with context. Now, we expect `NodeCategory.poll()` and `NodeItem.poll()` to always be called with a valid context (since when there is no context available, we can assume `poll()` is always True). `NodeCategory.items()`, however, must accept NULL context, so if you use custom `items` callable for your custom node categories, you may need to update it (as was done here for builtin `node_group_items()`).
This commit is contained in:
@@ -37,7 +37,7 @@ class NodeCategory:
|
||||
else:
|
||||
def items_gen(context):
|
||||
for item in items:
|
||||
if item.poll is None or item.poll(context):
|
||||
if item.poll is None or context is None or item.poll(context):
|
||||
yield item
|
||||
self.items = items_gen
|
||||
|
||||
@@ -136,7 +136,7 @@ def register_node_categories(identifier, cat_list):
|
||||
def node_categories_iter(context):
|
||||
for cat_type in _node_categories.values():
|
||||
for cat in cat_type[0]:
|
||||
if cat.poll and cat.poll(context):
|
||||
if cat.poll and ((context is None) or cat.poll(context)):
|
||||
yield cat
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user