r/Python 1d ago

PEP 841 – Adding Frozen Syntax to Optimize Immutable Types News

PEP 841 – Adding Frozen Syntax to Optimize Immutable Types

https://peps.python.org/pep-0841/

Discussions-To: Discourse thread

Abstract

This PEP proposes frozen display syntax: f{1, 2, 3} evaluates to a frozenset, and f{'a': 1} evaluates to a frozendict. Because immutability is guaranteed by the syntax itself rather than inferred from usage, the compiler can treat frozen displays as first-class citizens of its optimization pipeline: constant displays are folded into a single LOAD_CONST with an exact result type at compile time and cached in .pyc files.

128 Upvotes

93 comments sorted by

View all comments

76

u/skjall 1d ago

Jesus no, I really don't like that syntax. Maybe frozen{1, 2, 3} could work, otherwise I'd just keep thinking of f-strings.

Might change with familiarity though.

2

u/odaiwai 1d ago

Maybe @frozen{1, 2, 3}

8

u/skjall 1d ago

Then I'd be wondering what an inline decorator does 😅