flake8-bugbear
flake8-bugbear copied to clipboard
How about checking that you're not using a list for an in?
A very common pattern:
candidates = [some for some in another_stuff()]
if me in candidates:
do_stuff()
If candidates is only used for an in, then we have 2 alternatives that are going to be more performant than the above in 100% of the cases:
Using a generator:
-candidates = [some for some in another_stuff()]
+candidates = (some for some in another_stuff())
Or using a set:
-candidates = [some for some in another_stuff()]
+candidates = {some for some in another_stuff()}
How about linting this?
I like the intentions here, but feel it could be noisy.
Main reason: How do we know that the code does not need it to be a list elsewhere?
El dom, 18 de oct de 2020 a las 18:25, Cooper Lees [email protected] escribió:
Main reason: How do we know that the code does not need it to be a list elsewhere?
Maybe just checking that it is a local variable that goes out of scope without further usage? I don't know how complex that can be...