A literal constructor for frozensets [EDIT: already discussed in a PEP]

Structures such as lists, tuples, dictionaries, etc., have literal constructors,

assert [] == list()
assert () == tuple()
assert {} == dict()

but frozensets do not.

To distinguish this from a dictionary, and to expand on the following idea:

In a function, when declaring parameters between parentheses, you must specify the positional elements before the symbol /, which is the inverse of the asterisk (*) operator; a symbolic nod to math.

Why not generalize the concept within the curly braces, adding a / symbol that, when placed after the opening curly brace, means, “I’ve positioned all my elements up to this point”?

assert {1, 2, /} == frozenset({1, 2})
assert {/} == frozenset()

This offers yet another nod to math, as {/} is a combination of the two symbols representing the empty set: {} and ∅.

PS:

The idea originally came from wanting to create an empty set (not frozen) concisely, but in the end, quite a few ways of writing it (including simply calling the constructor with no arguments) work just fine, such as these:

set()
{*''}
{*{}}
...

I admit that all of this is just syntactic sugar, but Python is practically "evaluable pseudocode" that’s generally neither verbose nor “diabetic.” :*)

Welcome to DPO! Are you aware of PEP 802 – Display Syntax for the Empty Set and PEP 841 – Adding Frozen Syntax to Optimize Immutable Types? They seem to have substantial overlap with this proposal.

1 Like

Thank you very much for the quick response. I admit I hadn’t kept up with the PEPs up to the stable release (3.14); I should have done more research before posting my idea—my apologies.