flake8-pie icon indicating copy to clipboard operation
flake8-pie copied to clipboard

`foo or bar` instead of `foo if foo else bar`

Open sbdchd opened this issue 4 years ago • 1 comments

aka when checking the truthiness of the value, or is shorter

# err
foo if foo else bar
foo.buzz if foo.buzz else bar

# ok
foo.buzz if cond else bar
# essentially anytime the test in the if expression doesn't match the value being returned in the truthy case, we'd allow it
foo or bar

sbdchd avatar May 11 '21 14:05 sbdchd

This is somewhat tricky to implement as there isn't an easy way to compare the two AST trees to ensure they are equivalent

rel: https://github.com/sbdchd/flake8-pie/pull/84/files#diff-2cef682e5cbc4dc317854e5887d9f23ac9a3421cbb53a95f621808bcc8165244R8

sbdchd avatar Jun 26 '21 00:06 sbdchd