wemake-python-styleguide
wemake-python-styleguide copied to clipboard
Forbid chaining `is`
Rule request
Thesis
Forbid ast.Is
in ast.Compare.ops
when it's size is not zero. For example:
a = None
a is None # True, as expected
a is None is True # False 🤔
a is None == True # False 🤔
a is None is None # True 🤯
Reasoning
From the AST perspective, is
is an operator and can be chained. That can lead to unexpected results when the author wanted to compare the result of a is b
operation. Instead, Python will chain the operations and compare the last argument of the previous operation.
Also, I think the same applies to in
Yes, totally.
Hi, I'm new to contributing and would like to work on this issue.
If there is no progress on this issue, then I would like to implement it.
Hi, @lensvol! Happy to see you :)
@sobolevn You know me, can't stay away from a free T-shirt :)
Implemented in https://github.com/wemake-services/wemake-python-styleguide/pull/2527, please review.
If it is not resolved. I would like to work on this issue
@adlizone feel free :)
I think it is resolved in #2527, we just forgot to actualize the issue.