Skip to content

Simplify if cond: return True/False else: return False/True patterns#268

Merged
alejoe91 merged 1 commit into
SpikeInterface:mainfrom
yarikoptic:enh-return-bools
May 19, 2026
Merged

Simplify if cond: return True/False else: return False/True patterns#268
alejoe91 merged 1 commit into
SpikeInterface:mainfrom
yarikoptic:enh-return-bools

Conversation

@yarikoptic
Copy link
Copy Markdown
Contributor

@yarikoptic yarikoptic commented May 15, 2026

Summary

Seeing those code patterns triggerred me ;)

Small readability cleanup: replace several if cond: return True else: return False (and the inverse) constructs with a direct return cond (or return not cond, or a swapped ==/!=). No behavior change.

Commits

  • 5731ace Simplify if cond: return True/False else: return False/True patterns
Per-commit details

5731ace Simplify if cond: return True/False else: return False/True patterns

Refactored 6 instances across 3 files:

  • spikeinterface_gui/curationview.py — 3 methods (_conditional_refresh_merge / _delete / _split): if cond: return True else: return Falsereturn cond.
  • spikeinterface_gui/main.py (the SortingAnalyzer-folder check, both the non-zarr and zarr branches): if X != Y: return False else: return Truereturn X == Y (swapped != to ==).
  • spikeinterface_gui/view_base.py (is_warning_active): if active_window and isinstance(active_window, QT.QMessageBox): return True; return Falsereturn isinstance(active_window, QT.QMessageBox). isinstance(None, ...) already returns False, so the truthiness guard was redundant.

Left controller.py:check_is_view_possible alone because its if-branch has a side-effecting print, so the pattern doesn't simplify cleanly.

Test plan

  • python -m py_compile on the three edited files
  • Reviewer: spot-check the is_warning_active simplification — relying on isinstance(None, ...) being False

Replace verbose if/else-return-bool constructs with direct return
of the condition. In `is_warning_active`, drop the redundant
truthiness guard since `isinstance(None, ...)` already returns False.

Co-Authored-By: Claude Code 2.1.142 / Claude Opus 4.7 <noreply@anthropic.com>
@alejoe91 alejoe91 merged commit 5186578 into SpikeInterface:main May 19, 2026
2 checks passed
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.

2 participants