-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
bugSomething isn't workingSomething isn't workingruleImplementing or modifying a lint ruleImplementing or modifying a lint rule
Description
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}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingruleImplementing or modifying a lint ruleImplementing or modifying a lint rule