Combine collection predicates (ARCH2077)
Key python.performance.combine-collection-predicates · Severity info · Category performance
Consecutive filters can be fused into a single condition, and using any(...) instead of len(...) > 0 for an emptiness check avoids a needless full pass.
Incorrect
Section titled “Incorrect”def has_urgent(tickets): open_t = [t for t in tickets if t.is_open] urgent = [t for t in open_t if t.priority == "urgent"] return len(urgent) > 0Correct
Section titled “Correct”def has_urgent(tickets): return any(t.is_open and t.priority == "urgent" for t in tickets)Fuse consecutive filters into one condition and use any(...) for presence checks.