mirror of
https://github.com/astral-sh/ruff.git
synced 2025-12-04 01:36:46 +00:00
Closes https://github.com/charliermarsh/ruff/issues/2262 and closes https://github.com/charliermarsh/ruff/issues/2423 Fixes bug where some cases generated duplicated violations (see https://github.com/charliermarsh/ruff/pull/2732#issuecomment-1426397842)
1.5 KiB
1.5 KiB
unnecessary-double-cast-or-process (C414)
Derived from the flake8-comprehensions linter.
Autofix is always available.
What it does
Checks for unnecessary list, reversed, set, sorted, and tuple
call within list, set, sorted, and tuple calls.
Why is this bad?
It's unnecessary to double-cast or double-process iterables by wrapping
the listed functions within an additional list, set, sorted, or
tuple call. Doing so is redundant and can be confusing for readers.
Examples
list(tuple(iterable))
Use instead:
list(iterable)
This rule applies to a variety of functions, including list, reversed,
set, sorted, and tuple. For example:
- Instead of
list(list(iterable)), uselist(iterable). - Instead of
list(tuple(iterable)), uselist(iterable). - Instead of
tuple(list(iterable)), usetuple(iterable). - Instead of
tuple(tuple(iterable)), usetuple(iterable). - Instead of
set(set(iterable)), useset(iterable). - Instead of
set(list(iterable)), useset(iterable). - Instead of
set(tuple(iterable)), useset(iterable). - Instead of
set(sorted(iterable)), useset(iterable). - Instead of
set(reversed(iterable)), useset(iterable). - Instead of
sorted(list(iterable)), usesorted(iterable). - Instead of
sorted(tuple(iterable)), usesorted(iterable). - Instead of
sorted(sorted(iterable)), usesorted(iterable). - Instead of
sorted(reversed(iterable)), usesorted(iterable).