Skip to content

v0.2.2 - Detect Signal as Boolean (W031)

Latest

Choose a tag to compare

@calionauta calionauta released this 07 Mar 11:36

🆕 New Warning: W031

Detects: Signal Used as Python Boolean

Problem: Signals are always truthy in Python, breaking conditional logic at runtime.

Common Mistake:

(is_saving := Signal('is_saving', False))

# ❌ WRONG - Always shows 'Saving...' because Signal objects are truthy
Button('Save' if not is_saving else 'Saving...')

if is_saving:
    return 'Loading...'

Correct Fix:

# ✅ RIGHT - Use reactive attributes
Button(
    'Save this thought',
    data_text=is_saving.if_('Saving...', 'Save this thought')
)

Div(data_show=is_saving)  # Show/hide based on signal

📋 Detection Patterns

W031 flags these patterns:

  • if is_saving: ...
  • if not is_saving: ...
  • 'Save' if not is_saving else 'Saving...' (ternary)
  • while is_running: ...
  • if is_saving and is_valid: ...

🐛 Bug Fixed

This addresses a common runtime bug where button text or UI elements don't update correctly because the Signal object itself is being evaluated in Python, not its reactive value.

Before (broken):

Button('Save' if not is_saving else 'Saving...')  # Always 'Saving...'

After (working):

Button(data_text=is_saving.if_('Saving...', 'Save'))  # Reactive! ✅

📦 Installation

# Update existing install
starhtml-check --update

# Or fresh install
curl -L https://raw.githubusercontent.com/renatocaliari/starhtml-skill/main/starhtml_check.py \
  -o /usr/local/bin/starhtml-check && chmod +x /usr/local/bin/starhtml-check

Full changelog: v0.2.1...v0.2.2