Created
April 30, 2020 18:19
-
-
Save mallamanis/3a111706c1245db20748208895c3ee4b to your computer and use it in GitHub Desktop.
Prefer islice instead of list(...)[slice]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @name Use islice() to slice an iterable. | |
* @description instead of converting an iterable to a list and then slicing it | |
use `islice` for efficiency. | |
* @kind problem | |
* @tags maintainability | |
* @problem.severity recommendation | |
* @sub-severity low | |
* @precision high | |
* @tags speed | |
* @sub-severity low | |
* @id py/use-islice | |
*/ | |
import python | |
from Subscript subs | |
where | |
subs.getValue().(Call).getFunc().pointsTo(Value::named("list")) and | |
subs.getIndex() instanceof Slice | |
select subs, "Use `islice` instead." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment