This can make the code much less repetitive. It would be nice to do this with common code at the start of each branch, but this could be problematic if it affects the if expressions (although that shoudn’t be that common).
Maybe this could also apply to match statements. In both cases, there are easy-to-check sufficient conditions for exhaustiveness.
Example
# Bad
if x == 3:
print("foo")
print("bar")
elif x == 4:
print("foo5000")
print("bar")
else:
print("foobar")
print("bar")
# Good
if x == 3:
print("foo")
elif x == 4:
print("foo5000")
else:
y = 5
print("foobar")
print("bar")
Explanation
This can make the code much less repetitive. It would be nice to do this with common code at the start of each branch, but this could be problematic if it affects the if expressions (although that shoudn’t be that common).
Maybe this could also apply to match statements. In both cases, there are easy-to-check sufficient conditions for exhaustiveness.
Example