ruff
ruff copied to clipboard
UP034 false negative (not detected)
not detected:
ruff --isolated --select UP034 - <<<"set(('1.3.6.1.4.1.4203.666.11.1.4.2.12.1'),)"
expected:
-:1:5: UP034 Avoid extraneous parentheses
(pyupgrade doesn't catch it either.)
https://github.com/asottile/pyupgrade/issues/791
The behaviour wanted here is probably that of pylint's C0325. On https://github.com/charliermarsh/ruff/issues/970 C0325 is marked as completed due to UP034, but the scope of UP034 is much smaller so that doesn't seem correct.
The UP043 rule could be expanded to cover more cases, but it's not really related to pyupgrade's purpose, so IMO it would make sense just to implement the pylint rule separately.
EDIT: Actually, I don't think the pylint rule even catches the above case, although it still catches more than pyupgrade, and would make more sense to extend.
Any single statement with an operator is also not detected, which is consistent with pyupgrade:
ie: test = (1) + 2
Honestly, ruff UP034 doesn't catch anything for me. pylint catches all of these:
assert (a == b)
if (a == b):
while (a == b):
and returns
C0325: Unnecessary parens after 'if' keyword (superfluous-parens)
C0325: Unnecessary parens after 'while' keyword (superfluous-parens)
C0325: Unnecessary parens after 'assert' keyword (superfluous-parens)
ruff catches nothing.
Yeah I think they're just very different rules. I would describe UP034 as catching "redundant" parentheses, so, e.g., it will catch ((1)) + 2 but not (1) + 2. C0325 seems to catch "unnecessary" parentheses, i.e., all cases in which parentheses are not syntactically necessary, even if they may be used intentionally for readability or otherwise.
@charliermarsh Looking forward to when it is implemented. Currently the only thing I use pylint for is that check. Once it is added I can remove that dependency : ) I am pretty sure a --fix is possible as well and pylint doesn't do that. So it will be not only a replacement but an improvement : )
Thanks for all your work on this tool btw. I have never looked back since discovering it. I think I first heard about it on Talk Python to Me.
@codereport - Thank you for the kind words, so glad it's working well for you! (And yeah -- once implemented, we should be able to support autofix here.)