Alternative call syntax

Unfortunately {{ and }} are already currently used to denote a literal { and } in an f-string:

print(f'{{{1}}}') # outputs {1}

but if {{1}} is made to denote a frozenset of 1 then the above would become ambiguous.

1 Like

Not necessarily, you already need to write f'{ {1} }' to put a set in there. You would need to write f'{ {{1}} }' if that’s what you intended.

I feel like at some point we should swap out {{ with \{, but that wouldn’t be backwards compatible.

Good point. In a way f'{{1}}' is already ambiguous. I like the idea better than f{1, 2, 3} in theory then. But like @JamesParrott says, I don’t recall the last time I needed to define a frozenset literal either so I guess the real-world demand may not justify a syntax change.

I also want to point out that {{{1}}}, and {{{{1}}}}, … while all unambiguous, i.e. there is exactly one interpretation that doesn’t result in a runtime error, are imo confusing for human parsers. It also means that the lexer requires arbitrary lookahead to decide if it should parse {{{... as { {{ ... or {{ {...

1 Like

That’s exactly why we should NOT swap that out.

I will reiterate the advice you were already given: LISTEN a lot more than you speak. Or in this context, read a lot more than you write. Spend less time writing posts and more time reading through the archive. You will learn more and annoy fewer people.

More?

  • The outer one is a dict if an odd number of braces, everything else is
    a frozen set.

Obviously, the more complex cases get less visually clear, but (1) they
are not common cases, and (2) they are still unambigous, and will often
be made clearer by (a) the placement of closing brackets, and (b) decent
syntax highlighting.

From the mailing archive, didn’t get a response.

I should have worded that differently. “It would’ve been better if we needed to write \{ instead of {{, but changing that now wouldn’t be backwards compatible.”

And reading the archives and discussions is precisely what I’m doing now.

And you’ll find that there were good reasons for using the syntax that was chosen. This is what you keep on doing: stating opinions unfounded in fact, and thus implying that the people who originally made the decision must have blooped.

You mean f'{1 + 1}'? That’s just because they were parsed as regular strings '{1 + 1}' and evaluated afterwards.