Collapse if/else returning boolean literals
ProprietaryReplace if cond: return True / else: return False with return cond and the inverse with return not cond, including the fallthrough variant without an explicit else. A condition other than a comparison, a not, or an and/or of those is returned as bool(cond). The rewrite is declined on an elif, where bool is not the builtin, or where the removed statements hold comments.
org. openrewrite. python. cleanup. SimplifyBooleanReturnmod run . --recipe= org. openrewrite. python. cleanup. SimplifyBooleanReturnInstall it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.