-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
The autofix for PLW3301 generates incorrect code if the nested call is using a generator expression.
Example
PLW3301.py:
x = max(1, max(i for i in range(10)))Observed
ruff --isolated --diff --select PLW3301 PLW3301.py
--- PLW3301.py
+++ PLW3301.py
@@ -1 +1 @@
-x = max(1, max(i for i in range(10)))
+x = max(1, (i for i in range(10)))
Would fix 1 error.
Issue
This is incorrect. max takes either an iterable, or a variable number of arguments, but not both:
python -c "max(1, (i for i in range(10)))"
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: '>' not supported between instances of 'generator' and 'int'
Expected
The correct fix would be:
max(1, *(i for i in range(10)))
Ruff Version
ruff --version
ruff 0.0.267
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working