for-loop-set-mutations (FURB142)
Preview (since v0.3.5) · Related issues · View source
Derived from the refurb linter.
Fix is always available.
This rule is unstable and in preview. The --preview flag is required for use.
What it does
Checks for code that updates a set with the contents of an iterable by
using a for loop to call .add() or .discard() on each element
separately.
Why is this bad?
When adding or removing a batch of elements to or from a set, it's more idiomatic to use a single method call rather than adding or removing elements one by one.
Example
Use instead:
Fix safety
The fix will be marked as unsafe if applying the fix would delete any comments. Otherwise, it is marked as safe.