list-reverse-copy (FURB187)
Added in 0.5.0 · Related issues · View source
Derived from the refurb linter.
Fix is always available.
What it does
Checks for list reversals that can be performed in-place in lieu of creating a new list.
Why is this bad?
When reversing a list, it's more efficient to use the in-place method
.reverse() instead of creating a new list, if the original list is
no longer needed.
Example
Use instead:
Fix safety
This rule's fix is marked as unsafe, as calling .reverse() on a list
will mutate the list in-place, unlike reversed, which creates a new list
and leaves the original list unchanged.
If the list is referenced elsewhere, this could lead to unexpected behavior.