Skip to content

Fix operator precedence bug in condition unwrapping#233

Open
Mr-Neutr0n wants to merge 1 commit intoStability-AI:mainfrom
Mr-Neutr0n:fix/operator-precedence-bug
Open

Fix operator precedence bug in condition unwrapping#233
Mr-Neutr0n wants to merge 1 commit intoStability-AI:mainfrom
Mr-Neutr0n:fix/operator-precedence-bug

Conversation

@Mr-Neutr0n
Copy link

Summary

  • Fixes operator precedence bug in conditioners.py that caused incorrect condition unwrapping behavior
  • Without parentheses, Python evaluates A or B and C as A or (B and C), causing lists to always be unwrapped regardless of length

The Bug

Before (incorrect):

if isinstance(x[condition_key], list) or isinstance(x[condition_key], tuple) and len(x[condition_key]) == 1:

This unwraps:

  • All lists (regardless of length) - BUG!
  • Single-element tuples only

After (correct):

if (isinstance(x[condition_key], list) or isinstance(x[condition_key], tuple)) and len(x[condition_key]) == 1:

This correctly unwraps:

  • Single-element lists only
  • Single-element tuples only

This matches the intent described in the comment: "Unwrap the condition info if it's a single-element list or tuple"

Test plan

  • Verify that multi-element lists are no longer incorrectly unwrapped
  • Verify single-element lists and tuples are still properly unwrapped

Fixes #221

🤖 Generated with Claude Code

Add parentheses around the isinstance checks to ensure the condition
correctly checks for single-element lists OR tuples, rather than
the current buggy behavior of always unwrapping lists regardless
of length.

Fixes Stability-AI#221

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Mr-Neutr0n
Copy link
Author

Friendly bump! Let me know if there's anything I should update or improve to help move this forward.

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

Successfully merging this pull request may close these issues.

A bug?

1 participant