Skip extraction after wildcard imports

This commit is contained in:
2026-07-02 13:14:16 +02:00
parent b2b1bd16bd
commit c8c1205bde
2 changed files with 63 additions and 0 deletions
@@ -816,6 +816,57 @@ if True:
self.assertEqual({}, result["nodes"])
self.assertEqual("no_static_nodes", result["pack"]["status"])
def test_wildcard_import_before_mapping_skips_static_node_mapping(self):
source = '''
class WildcardBeforeMappingNode:
RETURN_TYPES = ("IMAGE",)
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"image": ("IMAGE",),
},
}
from something import *
NODE_CLASS_MAPPINGS = {
"WildcardBeforeMappingNode": WildcardBeforeMappingNode,
}
'''
result = self._extract_source(source, "wildcard-before-mapping-pack")
self.assertEqual({}, result["nodes"])
self.assertEqual("no_static_nodes", result["pack"]["status"])
def test_nested_wildcard_import_before_mapping_skips_static_node_mapping(self):
source = '''
class NestedWildcardBeforeMappingNode:
RETURN_TYPES = ("IMAGE",)
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"image": ("IMAGE",),
},
}
if True:
from something import *
NODE_CLASS_MAPPINGS = {
"NestedWildcardBeforeMappingNode": NestedWildcardBeforeMappingNode,
}
'''
result = self._extract_source(source, "nested-wildcard-before-mapping-pack")
self.assertEqual({}, result["nodes"])
self.assertEqual("no_static_nodes", result["pack"]["status"])
def test_dynamic_display_mapping_reassignment_falls_back_to_node_type(self):
source = '''
def build_displays():
+12
View File
@@ -273,6 +273,16 @@ def _has_wildcard_import_in_control_flow(stmt):
return found
def _has_module_wildcard_import(tree):
for stmt in tree.body:
if _has_wildcard_import(stmt):
return True
if isinstance(stmt, (ast.If, ast.For, ast.AsyncFor, ast.While, ast.Try, ast.With, ast.AsyncWith, ast.Match)):
if _has_wildcard_import_in_control_flow(stmt):
return True
return False
def _collect_module_env(tree):
env = {}
for stmt in tree.body:
@@ -509,6 +519,8 @@ def _final_module_dict(tree, env, name, value_converter):
def _node_class_mappings(tree, env):
if _has_module_wildcard_import(tree):
return {}
mappings = _final_module_dict(tree, env, "NODE_CLASS_MAPPINGS", _mapping_value_name)
return {str(node_type): class_name for node_type, class_name in mappings.items() if node_type and class_name}