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

WPS508 and chained comparisons

Open vnmabus opened this issue 3 years ago • 1 comments

What's wrong

The following code raises a WPS508 code (Found incorrect not with compare usage):

if not 1.5 < my_num < 3.75:
    ...

The alternative would be:

if my_num <= 1.5 or my_num >= 3.75:
    ...

which is probably harder to understand.

The problem is aggravated for longer chains of comparison, or if my_num was a function call (because in that case the second way is not even valid, as the function would be called multiple times).

How it should be

I think this error should not be raised for chained comparisons.

Flake8 version and plugins

Irrelevant.

pip information

Irrelevant.

OS information

Irrelevant.

vnmabus avatar Mar 14 '21 18:03 vnmabus

Same here. Left a comment to remind of the issue.

NChechulin avatar Oct 14 '22 11:10 NChechulin