mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
[flake8-comprehensions
] Handle trailing comma in fixes for unnecessary-generator-list/set
(C400
,C401
) (#15929)
The unsafe fixes for the rules [unnecessary-generator-list (C400)](https://docs.astral.sh/ruff/rules/unnecessary-generator-list/#unnecessary-generator-list-c400) and [unnecessary-generator-set (C401)](https://docs.astral.sh/ruff/rules/unnecessary-generator-set/#unnecessary-generator-set-c401) used to introduce syntax errors if the argument to `list` or `set` had a trailing comma, because the fix would retain the comma after transforming the function call to a comprehension. This PR accounts for the trailing comma when replacing the end of the call with a `]` or `}`. Closes #15852
This commit is contained in:
parent
076d35fb93
commit
c69b19fe1d
6 changed files with 155 additions and 16 deletions
|
@ -16,6 +16,17 @@ list((2 * x for x in range(3)))
|
|||
list(((2 * x for x in range(3))))
|
||||
list((((2 * x for x in range(3)))))
|
||||
|
||||
# Account for trailing comma in fix
|
||||
# See https://github.com/astral-sh/ruff/issues/15852
|
||||
list((0 for _ in []),)
|
||||
list(
|
||||
(0 for _ in [])
|
||||
# some comments
|
||||
,
|
||||
# some more
|
||||
)
|
||||
|
||||
|
||||
# Not built-in list.
|
||||
def list(*args, **kwargs):
|
||||
return None
|
||||
|
|
|
@ -26,6 +26,16 @@ set((2 * x for x in range(3)))
|
|||
set(((2 * x for x in range(3))))
|
||||
set((((2 * x for x in range(3)))))
|
||||
|
||||
# Account for trailing comma in fix
|
||||
# See https://github.com/astral-sh/ruff/issues/15852
|
||||
set((0 for _ in []),)
|
||||
set(
|
||||
(0 for _ in [])
|
||||
# some comments
|
||||
,
|
||||
# some more
|
||||
)
|
||||
|
||||
# Not built-in set.
|
||||
def set(*args, **kwargs):
|
||||
return None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue