Skip to content

useless-if-else (RUF034)#

This rule is unstable and in preview. The --preview flag is required for use.

What it does#

Checks for useless if-else conditions with identical arms.

Why is this bad?#

Useless if-else conditions add unnecessary complexity to the code without providing any logical benefit.

Assigning the value directly is clearer and more explicit, and should be preferred.

Example#

# Bad
foo = x if y else x

Use instead:

# Good
foo = x