I believe the most prominent argument against any empty set literal proposed up to now may be summarized as follows:
No existing syntax allows for the natural deduction of {*} (or {/}or any other proposal) as the empty set literal, unlike [], {}, () which all follow naturally from non-empty container syntax
An inconsistent syntax adds overhead for people learning the language and for people trying to write elegant code, and should only be considered if it also adds some significant value that outweighs the cost. While the mere non-existence of an empty set literal is also a form of inconsistency, the people in favor of the status quo seemed to deem that the lesser sin.
Please read the discussion above. The entire point about the appeal of {*} was that it can be made consistent across containers, and also consistent with unpacking.
Sidenote about font-ligatures, not a real proposal or argument.
Not as an argument against any proposal but rather as a thought for those that really want the empty set to stand out right now. (As in Iâm well aware of a whole host of arguments why this doesnât solve half of the problems people advocating real literals here wants to solve)
Getting a custom font-ligature transforming `set()` to a suitable glyph into one of the programmer fonts that have those might be an idea⊠(yeah remembering that you have to type something else does limit usability quite a bit but thatâs somewhat inherent in the ligature hack anywayâŠ)
Not true (IMO). The most prominent argument is simply that the benefits do not justify the costs.
The costs arenât subjective. Having a set literal and set() as equally valid ways of writing an empty set causes confusion, increases risk of âstyleâ arguments and junk PRs just changing from one to the other, and requires tutorials, courses and documentation to be modified. Making the new literal the officially preferred style requires changes to tutorials, documentation and courses, and adds pressure to maintainers of established projects to change to the new format in spite of the fact that doing so offers no actual benefit and causes backward compatibility issues. Making the set() form preferred reduces the benefits to almost nothing, and still adds confusion.
And the benefits? Some people get to use a literal form that they prefer over the current function call, and maybe thereâs a potential for a performance benefit. Thatâs not a lot.
Not being able to get consensus on the syntax of the literal is, frankly, irrelevant. It seems to mostly just give people something to debate so that they donât have to address the real issue (lack of meaningful benefits vs high costs).
Which is something that I have already acknowledged in a previous message and even may show support for, if it were to be discussed thoroughly.
My previous reply seems to have been interpreted as a rebuttal to your opinion; that was not my intention. I meant to clarify what the major argument against a new empty set literal was so that the discussion may stay on track.
That said, while I am in strong support of further discussing the two sets of syntax previously proposed, I wouldnât necessarily say that the community has reached consensus on the usefulness of Null Literal Unpacking. This thread is 9 months long, and most of the discussion in here has been focused on other topics.
This⊠actually aligns with what I was trying to get across. My unstated assumption was that if there actuallywere some obvious natural choice for the empty set literal, more people would agree that implementing the obvious choice into the language would reduce existing overhead enough to justify the aforementioned costs. (I concede that this statement is also subjective)
Ah, OK. I still disagree, though. Even if everyone thought {*} was the perfect way to spell an empty set literal, the fact that huge amounts of existing code uses set() means that adding a new spelling at this point would be more disruptive than itâs worth.
If we were just implementing sets for the first time now, the situation would be different. But weâre not, and the big body of existing code changes things.
For me, trying to make {*} not an outlier by adding [*] and {**} is more confusing than just accepting that the / in {/} is a special case. I can see the rational if I think about it long enough but it doesnât fit in my head at all.
I wrote that draft PEP about 1 year ago before this thread started because looked up history and discovered there was never strong enough reason to add empty set literal on itâs own.
So started trying to think of ways to add it indirectly while providing some other purpose and symmetry in the process.
The added benefit (*,) [*] {*} provides is thereâs a way to write empty tuple without parentheses (x = *,) and avoiding pitfall of forgetting comma when adding first element. You can either swap out the â*â or keep adding to the tuple without thinking about if you need trailing comma or not (x = *, 1). So this feature removes some special case semantics of tuple rather than adding more special cases to language for set.
Limiting the syntax to the first element of the literal means this could also be viewed as disambiguated leading comma. Also, limiting it to only non-map literals means the only place it wouldnât have a benefit is [] but can be avoided and only exists for symmetry.
I still think the empty set literal is useful for things like awkwardness in ast.literal_eval, repr of empty set is special case, avoiding builtin function call that can be shadowed/mocked, etc.
I will create an official PEP for this if any Python core developer would like to sponsor this direction.
Haha, yeah I can see that, note this proposal only applies to right hand side contexts. Maybe best way to think about it is in a repl with *().
My proposal would work same way using that which works today, but shortened to â*â compiled out of the resulting AST and possibly limited to first literal element position.
But maybe the compiler should have a special case which compiles out the *() idiom starred node inside literal containers completely, then get all the benefits without meaningfully changing language (but doubt anyone would learn this if not official syntax).
Edit: Have put up a issue/PR that optimizes the {*()} idiom regardless of any decision on this PEP or other related proposals. Very early on @AA-Turner had mentioned this optimization.