[flake8-comprehensions] Skip when TypeError present from too many (kw)args for C410,C411, and C418 (#15838)

Both `list` and `dict` expect only a single positional argument. Giving
more positional arguments, or a keyword argument, is a `TypeError` and
neither the lint rule nor its fix make sense in that context.

Closes #15810
This commit is contained in:
Dylan 2025-01-30 17:10:43 -06:00 committed by GitHub
parent fe516e24f5
commit 071862af5a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 52 additions and 8 deletions

View file

@ -11,3 +11,7 @@ list( # comment
list([ # comment
1, 2
])
# Skip when too many positional arguments
# See https://github.com/astral-sh/ruff/issues/15810
list([1],[2])

View file

@ -1,2 +1,8 @@
x = [1, 2, 3]
list([i for i in x])
# Skip when too many positional arguments
# or keyword argument present.
# See https://github.com/astral-sh/ruff/issues/15810
list([x for x in "XYZ"],[])
list([x for x in "XYZ"],foo=[])

View file

@ -8,3 +8,6 @@ dict(
dict({}, a=1)
dict({x: 1 for x in range(1)}, a=1)
# Skip when too many positional arguments
# See https://github.com/astral-sh/ruff/issues/15810
dict({"A": 1}, {"B": 2})