Open LordAro opened 2 weeks ago
Hi @LordAro
I'm struggling to understand how your question relates to C409
because the rule doesn't trigger for me with the given code example (see this playground). However, your example raises C408
and the rule recommends using literal syntax over function calls.
Raising C408
for tuple
is exactly the intent of the rule. That's why I don't think they should be excluded regardless of their position (see the rule documentation for the motivation). You can disable C408
when you prefer the method form.
Ah, I screwed up the numbers when constructing this example didn't I? I've updated the original issue
C408 pertains to all collection types - I'm saying that empty tuples specifically could be a special case because the syntax ( ()
) is used for so much else
Although tbh maybe it's more relevant for 1-length tuples, as (foo)
isn't a tuple but (foo, )
is
Thanks for updating the issue. Glad to hear that we're talking about the same :)
I agree, ()
is very unambiguous. I can see how (foo,)
is harder to spot. But the rule isn't just about readability:
It's unnecessary to call, e.g., dict() as opposed to using an empty literal ({}). The former is slower because the name dict must be looked up in the global scope in case it has been rebound.
That's why I still think we should keep flagging all tuples, including zero and one element tuples because it applies to them as well.
It's totally valid but
()
is a bit of a strange syntax to actually spawn an empty tuple, especially when it's used within another call. e.g.I suggest adding a setting to allow empty tuples, but possibly just allowing it generally.
Ruff version: 0.7.0