Closed fabien-michel closed 1 year ago
I'm not sure the W8401 should trigger when a walrus operator is implied in the condition.
The warning appear for this code.
def odd_only(a): if a % 2: return a return False filtered = [] for a in range(1, 5): if b := odd_only(a): filtered.append(b)
Which should be changed to
filtered = [b for a in range(1, 5) if (b := odd_only(a))]
I'm found this kind of code not clear, because of the walrus operator.
The workaround is to not use the walrus operator:
filtered = [] for a in range(1, 5): b = odd_only(a) if b: filtered.append(b)
So, as there is an equivalence, and the warn is not triggered, it should also not warn when a walrus operator is used.
I'm not sure the W8401 should trigger when a walrus operator is implied in the condition.
The warning appear for this code.
Which should be changed to
I'm found this kind of code not clear, because of the walrus operator.
The workaround is to not use the walrus operator:
So, as there is an equivalence, and the warn is not triggered, it should also not warn when a walrus operator is used.