freenodenews
Languages & Toolchains

Python PEP 841 frozen literals hit ordering and syntax pushback

A proposal for frozenset and frozendict display syntax draws fire over constant folding, the f-prefix, and whether the types are ready for first-class spelling.

Python developers are weighing PEP 841, which would add frozen literal syntax so frozenset and frozendict values can be written as compact displays instead of constructor calls. The change is pitched both as a usability win for immutable collections and as a way to unlock constant-time optimizations the current call forms cannot guarantee.

Alyssa Coghlan flagged a concrete technical problem. The draft said frozen constants would share objects under the usual code-object constant deduplication rules, with frozendict equality ignoring insertion order. That would make the iteration order of a frozen dict display ambiguous: two equal displays written in different key orders inside one code block could collapse to a single object, breaking the ordering guarantees that the existing frozendict constructor provides. Co-author Donghee Na agreed the behavior is unacceptable and said the PEP will be revised to preserve those guarantees.

Beyond that fix, reaction split on motivation and spelling. Several participants argued the draft leans too hard on micro-optimization and underplays the simpler case for treating immutable collections as syntactic equals of their mutable counterparts. Others questioned whether dedicated syntax is premature at all, noting that frozendict is not yet in a released CPython and that new literal forms raise the reading burden for everyone who encounters them, not only for the functional-style users who would type them most.

The proposed f{...} prefix drew particular resistance. Critics said it overloads the f marker already used for format strings and sits awkwardly beside brace-delimited sets and dicts, whose usual neighbors are brackets and parentheses rather than letter prefixes. Alternatives such as {|...|} or {|...} have been floated; the authors said they are open to a second round on spelling once the broader question of whether frozen literals belong in the language is settled.

That sequencing question is now the practical fork. Supporters want a shortlist of acceptable spellings and a clear yes-or-no on whether the feature is worth any of them. Skeptics want evidence that frozenset and frozendict usage will justify permanent syntax before the language commits to another display form.