readlines-in-for (FURB129)
Derived from the refurb linter.
Fix is always available.
What it does
Checks for uses of readlines()
when iterating over a file line-by-line.
Why is this bad?
Rather than iterating over all lines in a file by calling readlines()
,
it's more convenient and performant to iterate over the file object
directly.
Example
Use instead:
Fix safety
This rule's fix is marked as unsafe if there's comments in the
readlines()
call, as comments may be removed.
For example, the fix would be marked as unsafe in the following case: