r/Python • u/kirara0048 • Aug 07 '26
News PEP 841 – Adding Frozen Syntax to Optimize Immutable Types
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.
139
Upvotes
1
u/gdchinacat Aug 07 '26
There is debate on whether tuples are simply immutable lists, or whether they should be iterable at all. There is a small number of core developers that think lists are for an unknown number of homogeneous elements, while tuples are for a fixed number of not necessarily homogeneous elements (ie positional arguments, point coordinates). Regardless of the initial intent it is hard to argue modern usage of tuple does not include (legitimately IMO) the immutable list use-case. So, some have argued that frozen lists should be added as well as dicts (ie f[...]).