https://github.com/python/cpython/commit/0bbdb4e897ae909af39cd93f7a25de89b724ab47
commit: 0bbdb4e897ae909af39cd93f7a25de89b724ab47
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-02-18T20:23:49Z
summary:

gh-141510: Replace MappingProxyType with frozendict (#144904)

files:
M Lib/dataclasses.py
M Lib/email/headerregistry.py
M Lib/test/support/hashlib_helper.py
M Lib/test/test_dataclasses/__init__.py
M Lib/test/test_hmac.py

diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index 730ced7299865e..482a4c61039184 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -191,8 +191,8 @@ class _KW_ONLY_TYPE:
 KW_ONLY = _KW_ONLY_TYPE()
 
 # Since most per-field metadata will be unused, create an empty
-# read-only proxy that can be shared among all fields.
-_EMPTY_METADATA = types.MappingProxyType({})
+# read-only dictionary that can be shared among all fields.
+_EMPTY_METADATA = frozendict()
 
 # Markers for the various kinds of fields and pseudo-fields.
 class _FIELD_BASE:
diff --git a/Lib/email/headerregistry.py b/Lib/email/headerregistry.py
index 0e8698efc0b966..48cd85a65ba9f6 100644
--- a/Lib/email/headerregistry.py
+++ b/Lib/email/headerregistry.py
@@ -3,8 +3,6 @@
 This module provides an implementation of the HeaderRegistry API.
 The implementation is designed to flexibly follow RFC5322 rules.
 """
-from types import MappingProxyType
-
 from email import utils
 from email import errors
 from email import _header_value_parser as parser
@@ -462,7 +460,7 @@ def init(self, *args, **kw):
 
     @property
     def params(self):
-        return MappingProxyType(self._params)
+        return frozendict(self._params)
 
 
 class ContentTypeHeader(ParameterizedMIMEHeader):
diff --git a/Lib/test/support/hashlib_helper.py 
b/Lib/test/support/hashlib_helper.py
index 49077d7cb4d757..818f99d0023dae 100644
--- a/Lib/test/support/hashlib_helper.py
+++ b/Lib/test/support/hashlib_helper.py
@@ -6,7 +6,6 @@
 import unittest
 import unittest.mock
 from test.support import import_helper
-from types import MappingProxyType
 
 
 def _parse_fullname(fullname, *, strict=False):
@@ -351,7 +350,7 @@ def __init__(
         )
 
 
-_HASHINFO_DATABASE = MappingProxyType({
+_HASHINFO_DATABASE = frozendict({
     _HashId.md5: _HashInfo(
         _HashId.md5,
         "_md5.MD5Type",
@@ -500,7 +499,7 @@ def _iter_hash_func_info(excluded):
 # keyed hash function. However, as it's exposed by HACL*, we test it.
 _HMACINFO_DATABASE[_HashId.blake2s] = _HashInfoItem('_hmac.compute_blake2s_32')
 _HMACINFO_DATABASE[_HashId.blake2b] = _HashInfoItem('_hmac.compute_blake2b_32')
-_HMACINFO_DATABASE = MappingProxyType(_HMACINFO_DATABASE)
+_HMACINFO_DATABASE = frozendict(_HMACINFO_DATABASE)
 assert _HMACINFO_DATABASE.keys() == CANONICAL_DIGEST_NAMES
 
 
diff --git a/Lib/test/test_dataclasses/__init__.py 
b/Lib/test/test_dataclasses/__init__.py
index 3b335429b98500..8b5e0cf7806ba9 100644
--- a/Lib/test/test_dataclasses/__init__.py
+++ b/Lib/test/test_dataclasses/__init__.py
@@ -71,7 +71,7 @@ def test_field_repr(self):
         expected_output = "Field(name='id',type=None," \
                            f"default=1,default_factory={MISSING!r}," \
                            "init=True,repr=False,hash=None," \
-                           "compare=True,metadata=mappingproxy({})," \
+                           "compare=True,metadata=frozendict()," \
                            f"kw_only={MISSING!r}," \
                            "doc='Docstring'," \
                            "_field_type=None)"
diff --git a/Lib/test/test_hmac.py b/Lib/test/test_hmac.py
index 17888a9f286c8f..de4d200374bcea 100644
--- a/Lib/test/test_hmac.py
+++ b/Lib/test/test_hmac.py
@@ -21,7 +21,6 @@
 import hmac
 import hashlib
 import random
-import types
 import unittest
 import warnings
 from _operator import _compare_digest as operator_compare_digest
@@ -303,7 +302,7 @@ def assert_hmac_new_by_name(
 
     def check_hmac_new(
         self, key, msg, hexdigest, hashname, digest_size, block_size,
-        hmac_new_func, hmac_new_kwds=types.MappingProxyType({}),
+        hmac_new_func, hmac_new_kwds=frozendict(),
     ):
         """Check that HMAC(key, msg) == digest.
 
@@ -349,7 +348,7 @@ def assert_hmac_hexdigest_by_name(
 
     def check_hmac_hexdigest(
         self, key, msg, hexdigest, digest_size,
-        hmac_digest_func, hmac_digest_kwds=types.MappingProxyType({}),
+        hmac_digest_func, hmac_digest_kwds=frozendict(),
     ):
         """Check and return a HMAC digest computed by hmac_digest_func().
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to