Skip to content

Instantly share code, notes, and snippets.

@mallamanis
Created April 30, 2020 18:19
Show Gist options
  • Save mallamanis/3a111706c1245db20748208895c3ee4b to your computer and use it in GitHub Desktop.
Save mallamanis/3a111706c1245db20748208895c3ee4b to your computer and use it in GitHub Desktop.
Prefer islice instead of list(...)[slice]
/**
* @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