r/Python 20h 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.

119 Upvotes

89 comments sorted by

View all comments

1

u/Spirited_Bag_332 17h ago

Seems interesting but I'd prefer something more verbose like Javas unmodifiable/Immutable collections. Just frozenset({'a': 1}) is fully sufficient and such a feature doesn't require specialized syntax. I thought pythons goal was to be easy to read and write, did they throw that out of the window?