Skip to content

Instantly share code, notes, and snippets.

@mallamanis
Created April 30, 2020 18:01
Show Gist options
  • Save mallamanis/8eaf1eac5509e583fbf60df302f70cf2 to your computer and use it in GitHub Desktop.
Save mallamanis/8eaf1eac5509e583fbf60df302f70cf2 to your computer and use it in GitHub Desktop.
Prefer iglob instead of glob
/**
* @name Prefer iglob
* @description Use iglob instead of glob
* @kind problem
* @tags speed
* @problem.severity recommendation
* @sub-severity low
* @precision high
* @id py/use-iglob
*/
import python
predicate is_glob(Call call) {
call.getFunc().pointsTo(Value::named("glob.glob"))
}
from AstNode node
where
is_glob(node.(For).getIter().(Call)) or
is_glob(node.(ListComp).getIterable()) or
is_glob(node.(SetComp).getIterable()) or
is_glob(node.(DictComp).getIterable()) or
is_glob(node.(GeneratorExp).getIterable())
select node, "Prefer `iglob` to `glob`"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment