[Python-ideas] frozenset literals

random832 at fastmail.us random832 at fastmail.us
Wed Feb 13 22:02:50 CET 2013


On Sat, Feb 2, 2013, at 9:20, Steven D'Aprano wrote:
> Unfortunately the proposal to use f{ ... } for frozen sets cannot work
> within the constraints of Python's lexer:
> 
> http://mail.python.org/pipermail/python-3000/2008-January/011838.html
> 
> Unfortunately we're running out of useful, easy to enter symbols for
> literals. Until such time (Python4000 perhaps, or more likely Python5000)
> as we can use a rich set of Unicode literals, I don't think there is any
> clear way to have a frozenset literal.

I was going to post about not being sure what the objection is (if it's
multiple tokens, let it be multiple tokens - the contents are multiple
tokens anyway - and saying it would block a future syntax extension
doesn't seem like a reasonable objection to a proposed syntax
extension), but I had a new idea so I'll post that instead:

{ as frozenset { ... } }

The sequence "{ as" can't occur (to my knowledge) anywhere now. So, the
thing after it is a keyword in that context (and only that context,
otherwise "frozenset" remains an identifier naming an ordinary builtin)
and specifies what kind of literal the following sequence is. You could
also extend it to alternate forms for some other builtin types - for
example { as bytes [1, 2, 3, 4, 5] } instead of b"\x1\x2\x3\x4\x5".
Or... { as set { } }



More information about the Python-ideas mailing list