
See also the rejected PEP 351. -- Eric
On Jan 20, 2022, at 7:21 PM, Cameron Simpson <cs@cskk.id.au> wrote:
Well, I've just waded through this discussion.
This all feels to me like a special case of "wanting a constant for bytecode". What is we had a "freeze" operator, eg:
|foo|
which would produce a frozen version of foo. I'm liking the vertical bars myself, I think because it feels vaguely slightly analogous to "absolute value". So (assuming we can squeeze it into the expression syntax):
|{1,2,3}|
always makes a direct frozen set on the same basis that:
x in {1,2,3}
directly makes a frozenset by expression inspection. Then
Paired with a __freeze__ dunder method, this applies to any type, not just sets. (Where appropriate of course.)
So:
|{1,2,3}| frozen set |[1,2,3]| tuple! |any-iterable| tuple! |{1:2, 3:4}| frozen dict
Ths saves us (a) inventing a special syntax for frozen sets and (b) gateways to freezing many things, starting with the obvious above, via the __freeze__ dunder method.
This feels more general and less bikeshedable.
My main question is: is the syntax unambiguous?
Cheers, Cameron Simpson <cs@cskk.id.au> _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/2RW36I... Code of Conduct: http://python.org/psf/codeofconduct/