Simplify if cond: return True/False else: return False/True patterns#268
Open
yarikoptic wants to merge 1 commit into
Open
Simplify if cond: return True/False else: return False/True patterns#268yarikoptic wants to merge 1 commit into
yarikoptic wants to merge 1 commit into
Conversation
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
approved these changes
May 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 directreturn cond(orreturn not cond, or a swapped==/!=). No behavior change.Commits
Simplify if cond: return True/False else: return False/True patternsPer-commit details
5731ace
Simplify if cond: return True/False else: return False/True patternsRefactored 6 instances across 3 files:
spikeinterface_gui/curationview.py— 3 methods (_conditional_refresh_merge/_delete/_split):if cond: return True else: return False→return cond.spikeinterface_gui/main.py(the SortingAnalyzer-folder check, both the non-zarr and zarr branches):if X != Y: return False else: return True→return X == Y(swapped!=to==).spikeinterface_gui/view_base.py(is_warning_active):if active_window and isinstance(active_window, QT.QMessageBox): return True; return False→return isinstance(active_window, QT.QMessageBox).isinstance(None, ...)already returnsFalse, so the truthiness guard was redundant.Left
controller.py:check_is_view_possiblealone because itsif-branch has a side-effectingprint, so the pattern doesn't simplify cleanly.Test plan
python -m py_compileon the three edited filesis_warning_activesimplification — relying onisinstance(None, ...)being False