Skip to content

Commit 34eda0f

Browse files
authored
fix: remove redundant useless loop (Comfy-Org#4656)
fix: potential error of undefined variable Comfy-Org#4650
1 parent d31e226 commit 34eda0f

3 files changed

Lines changed: 26 additions & 29 deletions

File tree

script_examples/websockets_api_example.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ def get_images(ws, prompt):
4141
continue #previews are binary data
4242

4343
history = get_history(prompt_id)[prompt_id]
44-
for o in history['outputs']:
45-
for node_id in history['outputs']:
46-
node_output = history['outputs'][node_id]
47-
if 'images' in node_output:
48-
images_output = []
49-
for image in node_output['images']:
50-
image_data = get_image(image['filename'], image['subfolder'], image['type'])
51-
images_output.append(image_data)
52-
output_images[node_id] = images_output
44+
for node_id in history['outputs']:
45+
node_output = history['outputs'][node_id]
46+
images_output = []
47+
if 'images' in node_output:
48+
for image in node_output['images']:
49+
image_data = get_image(image['filename'], image['subfolder'], image['type'])
50+
images_output.append(image_data)
51+
output_images[node_id] = images_output
5352

5453
return output_images
5554

tests/inference/test_execution.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,16 @@ def run(self, graph):
9595
pass # Probably want to store this off for testing
9696

9797
history = self.get_history(prompt_id)[prompt_id]
98-
for o in history['outputs']:
99-
for node_id in history['outputs']:
100-
node_output = history['outputs'][node_id]
101-
result.outputs[node_id] = node_output
102-
if 'images' in node_output:
103-
images_output = []
104-
for image in node_output['images']:
105-
image_data = self.get_image(image['filename'], image['subfolder'], image['type'])
106-
image_obj = Image.open(BytesIO(image_data))
107-
images_output.append(image_obj)
108-
node_output['image_objects'] = images_output
98+
for node_id in history['outputs']:
99+
node_output = history['outputs'][node_id]
100+
result.outputs[node_id] = node_output
101+
images_output = []
102+
if 'images' in node_output:
103+
for image in node_output['images']:
104+
image_data = self.get_image(image['filename'], image['subfolder'], image['type'])
105+
image_obj = Image.open(BytesIO(image_data))
106+
images_output.append(image_obj)
107+
node_output['image_objects'] = images_output
109108

110109
return result
111110

tests/inference/test_inference.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,14 @@ def get_images(self, graph, save=True):
109109
continue #previews are binary data
110110

111111
history = self.get_history(prompt_id)[prompt_id]
112-
for o in history['outputs']:
113-
for node_id in history['outputs']:
114-
node_output = history['outputs'][node_id]
115-
if 'images' in node_output:
116-
images_output = []
117-
for image in node_output['images']:
118-
image_data = self.get_image(image['filename'], image['subfolder'], image['type'])
119-
images_output.append(image_data)
120-
output_images[node_id] = images_output
112+
for node_id in history['outputs']:
113+
node_output = history['outputs'][node_id]
114+
images_output = []
115+
if 'images' in node_output:
116+
for image in node_output['images']:
117+
image_data = self.get_image(image['filename'], image['subfolder'], image['type'])
118+
images_output.append(image_data)
119+
output_images[node_id] = images_output
121120

122121
return output_images
123122

0 commit comments

Comments
 (0)