Skip to content

Split or ifs

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Splits out conditions combined with an or in an if statement into their own if statement.

if a or b:
c()
if a:
c()
elif b:
c()

It is logically equivalent to transform an or condition into an if branch and an elif branch of a conditional. This is not prima facie an improvement to the code, but it can unlock further improvements, and Sourcery will only make this change if such improvements are possible.