Fix is always available.
What it does#
Checks for uses of
list(...) that can be replaced with
Why is this bad?#
list(...) will create a new list of the entire collection, which
can be very expensive for large collections. If you only need the first
element of the collection, you can use
lazily fetch the first element.
This rule's fix is marked as unsafe, as migrating from
next(iter(...)) can change the behavior of your program in two ways:
list(...)will eagerly evaluate the entire collection, while
next(iter(...))will only evaluate the first element. As such, any side effects that occur during iteration will be delayed.
IndexErrorif the collection is empty, while