`frozenset` and `frozendict` comprehensions

There’s also some discussion on the notation in the PEP proposal thread PEP 841: Adding Frozen Syntax to Make Immutable Types Optimizable - #48 by blhsing

As said in PEP 841: Adding Frozen Syntax to Make Immutable Types Optimizable - #50 by timhoffm, it’s generally a good idea to decouple

  • whether frozen literals provide enough benefit
  • what would be a good syntax if one wanted to add frozen literals

If we do a poll for the second, we should have a shortlist of reasonable candidates to choose from. I propose:

Consider:

  • f{"a", "b"} - short but a bit similar to f-strings
  • i{"a", "b"} - short and not similar to f-strings, but maybe immutiable is a slightly worse mnemonic because the object is called frozen not immutable
  • {|"a", "b"|} - a two-char bracket not a prefix-modifier

Maybe consider:

  • frozen{"a", "b"}, fr{"a", "b"}: longer word prefixes - may be easier to understand and discern from f-strings, but are more verbose
  • {|"a", "b"} - an “inner” prefix-modifier - a bit unusual but not a no-go

Do not consider:

  • ${"a", "b"}: no new symbol
  • |{"a", "b"}| or +{"a", "b"}: no symbols that are operators outside the braces
  • {{"a", "b"}}: already valid syntax

Overall, any syntax has to be learned, so the key aspects are how easy it is to identify (discern from other code constructs) and to remember.

1 Like