flake8-comprehensions icon indicating copy to clipboard operation
flake8-comprehensions copied to clipboard

Detect `set({})` calls

Open bluetech opened this issue 5 months ago • 3 comments
trafficstars

Description

I have seen this a few times. {...} is a literal set so seems reasonable to warn about set({}) in addition to set([]) and set(()).

bluetech avatar May 27 '25 13:05 bluetech

Yeah, this could be cool. Since I'm mostly using Ruff now, though, I would rather that we just develop the rule there...

adamchainz avatar May 29 '25 22:05 adamchainz

No problem! In the Ruff discussion, we're not sure where to add it. If you were to implement it in flake8-comprehensions, would you add it to an existing rule, or as a new rule?

bluetech avatar May 30 '25 09:05 bluetech

I don't have a strong opinion, but I lean towards a new rule, mainly because set literal syntax was only added in Python 2.7/3.1. That means set([...]) and set((...)) may come from historical code that wasn't redundant at the time, but set({...}) comes from modern code that was written redundantly.

adamchainz avatar May 30 '25 14:05 adamchainz