Skip to content

C410, C411, and C418 have false positives for calls with extra arguments #15810

@dscorbett

Description

@dscorbett

Description

unnecessary-literal-within-list-call (C410), unnecessary-list-call (C411), and unnecessary-literal-within-dict-call (C418) have false positives in Ruff 0.9.3 when the list or dict call has too many positional arguments or (for C411) there is a keyword argument. Their fixes suppress TypeErrors.

$ cat >c41.py <<'# EOF'
try:
    print(list([1], [2]))
except TypeError as e:
    print(e)
try:
    print(list([x for x in "XYZ"], []))
except TypeError as e:
    print(e)
try:
    print(list([x for x in "XYZ"], foo=[]))
except TypeError as e:
    print(e)
try:
    print(dict({"A": 1}, {"B": 2}))
except TypeError as e:
    print(e)
# EOF

$ python c41.py
list expected at most 1 argument, got 2
list expected at most 1 argument, got 2
list() takes no keyword arguments
dict expected at most 1 argument, got 2

$ ruff --isolated check  --select C410,C411,C418 c41.py --unsafe-fixes --fix
Found 4 errors (4 fixed, 0 remaining).

$ cat c41.py
try:
    print([1])
except TypeError as e:
    print(e)
try:
    print([x for x in "XYZ"])
except TypeError as e:
    print(e)
try:
    print([x for x in "XYZ"])
except TypeError as e:
    print(e)
try:
    print({"A": 1})
except TypeError as e:
    print(e)

$ python c41.py
[1]
['X', 'Y', 'Z']
['X', 'Y', 'Z']
{'A': 1}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions