Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redundant Outer Loop and Potential Bug in get_images Function #3

Open
2ndpic opened this issue Aug 28, 2024 · 1 comment
Open

Redundant Outer Loop and Potential Bug in get_images Function #3

2ndpic opened this issue Aug 28, 2024 · 1 comment

Comments

@2ndpic
Copy link

2ndpic commented Aug 28, 2024

Link to the code

for o in history['outputs']:
    for node_id in history['outputs']:
        node_output = history['outputs'][node_id]
        if 'images' in node_output:
            images_output = []
            for image in node_output['images']:
                image_data = get_image(image['filename'], image['subfolder'], image['type'])
                images_output.append(image_data)
        output_images[node_id] = images_output

First, I believe the outer loop for o in history['outputs']: is redundant and can be removed. This loop seems to serve no practical purpose as it merely iterates over the length of history['outputs'] without performing any operations on each element.

Secondly, I think images_output = [] should be placed above the condition if 'images' in node_output:. The current code structure will result in an error local variable 'images_output' referenced before assignment when the if condition is false.

Can the author or community members explain if there are any additional considerations for this code, or if it was simply written in error? Thank you!

Suggested modification:

for node_id in history['outputs']:
    node_output = history['outputs'][node_id]
    images_output = []  # Initialize images_output here
    if 'images' in node_output:
        for image in node_output['images']:
            image_data = get_image(image['filename'], image['subfolder'], image['type'])
            images_output.append(image_data)
    output_images[node_id] = images_output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@2ndpic and others