wemake-python-styleguide icon indicating copy to clipboard operation
wemake-python-styleguide copied to clipboard

Enforce consistent ternary expressions

Open sobolevn opened this issue 4 years ago • 1 comments

Rule request

Thesis

We need to fix how we write ternary expressions, currently it has too many options:

some = other if x > 1 else None
some = (
    other 
    if x > 1 else None
)
some = (
    other 
    if x > 1 
    else None
)
some = (
    other if x > 1 
    else None
)
some = other if x > 1 
    else None

Probably, there are other cases as well.

So, we should decide which ones we allow and which ones are going to be violations. I know that single line ternary is always good.

To decide - we can analyze the code inside this project.

Related #1266 Related #1706

sobolevn avatar Feb 26 '21 08:02 sobolevn

I like this one:

some = (
    other 
    if x > 1 
    else None
)

sobolevn avatar Aug 22 '21 12:08 sobolevn