Skip extraction after wildcard imports
This commit is contained in:
@@ -816,6 +816,57 @@ if True:
|
|||||||
self.assertEqual({}, result["nodes"])
|
self.assertEqual({}, result["nodes"])
|
||||||
self.assertEqual("no_static_nodes", result["pack"]["status"])
|
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):
|
def test_dynamic_display_mapping_reassignment_falls_back_to_node_type(self):
|
||||||
source = '''
|
source = '''
|
||||||
def build_displays():
|
def build_displays():
|
||||||
|
|||||||
@@ -273,6 +273,16 @@ def _has_wildcard_import_in_control_flow(stmt):
|
|||||||
return found
|
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):
|
def _collect_module_env(tree):
|
||||||
env = {}
|
env = {}
|
||||||
for stmt in tree.body:
|
for stmt in tree.body:
|
||||||
@@ -509,6 +519,8 @@ def _final_module_dict(tree, env, name, value_converter):
|
|||||||
|
|
||||||
|
|
||||||
def _node_class_mappings(tree, env):
|
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)
|
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}
|
return {str(node_type): class_name for node_type, class_name in mappings.items() if node_type and class_name}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user