Skip to content

unnecessary-collection-call

Pythonstyleno fixdefault: offpython/ruff

Reports dict(), list() or tuple() with no arguments, and dict(a=1) with only keyword arguments.

A literal ({}, [], (), {"a": 1}) says the same, needs no name lookup and call, and is faster.

To fix, write the literal.

Reported
...
pprint(3)
x = dict()
x = dict(a=1)
x = dict(**a)
x = dict(a, b=1)
x = list()
x = tuple()
x = list(a)
...
python:
lint:
rules:
unnecessary-collection-call: warn # off (default), warn, error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line unnecessary-collection-call in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff C408 full