PSA: i’d like to add a mypy lint for it, but: an i...
# development
w
PSA: i’d like to add a mypy lint for it, but: an important rule of thumb in
@rules
is:
Never iterate over a
set
, except to sort it OR to create another
set
(or use
(Frozen)OrderedSet
in the first place).
see https://github.com/pantsbuild/pants/issues/14195#issuecomment-1114087237 for background
b
To understand, iterating over a set isn't bad, but iterating over it and using the result of the iteration in something that is sequenced and cached is (because of cache misses on varying sequences of the same data)?
w
yea. but almost everything eventually becomes a
Process
input.
you could maybe punch another caveat in the rule of thumb for “except to sort it OR to create another set”
b
We could always just yeet
set
and enforce an ordered set implementation?
w
they’re fine to use for membership checks: `x in myset`… it’s just iteration that’s potentially problematic.
1
afaict, it’s possible to write a lint for iteration
b
This sounds like a caveat worth including in the Contributing section of the docs.