]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-141510: Replace MappingProxyType with frozendict (#144904)
authorVictor Stinner <vstinner@python.org>
Wed, 18 Feb 2026 20:23:49 +0000 (21:23 +0100)
committerGitHub <noreply@github.com>
Wed, 18 Feb 2026 20:23:49 +0000 (20:23 +0000)
Lib/dataclasses.py
Lib/email/headerregistry.py
Lib/test/support/hashlib_helper.py
Lib/test/test_dataclasses/__init__.py
Lib/test/test_hmac.py

index 730ced7299865ecc71d30d9552bf9597dd2d41a1..482a4c610391842980a3dd06b56ab043635a613a 100644 (file)
@@ -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:
index 0e8698efc0b96676c79a656fc49a9f6e1492807d..48cd85a65ba9f617bc6cf150b042d068af4db841 100644 (file)
@@ -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 @@ class ParameterizedMIMEHeader:
 
     @property
     def params(self):
-        return MappingProxyType(self._params)
+        return frozendict(self._params)
 
 
 class ContentTypeHeader(ParameterizedMIMEHeader):
index 49077d7cb4d75796d86b9707f2392610df91a01d..818f99d0023dae930fe0df455139287eedd75395 100644 (file)
@@ -6,7 +6,6 @@ import inspect
 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 @@ class _HashInfo:
         )
 
 
-_HASHINFO_DATABASE = MappingProxyType({
+_HASHINFO_DATABASE = frozendict({
     _HashId.md5: _HashInfo(
         _HashId.md5,
         "_md5.MD5Type",
@@ -500,7 +499,7 @@ _HMACINFO_DATABASE[_HashId.shake_256] = _HashInfoItem()
 # 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
 
 
index 3b335429b9850062fe54f80339932335dbebbc4a..8b5e0cf7806ba93fb7c617c86802ceaf81e10cc5 100644 (file)
@@ -71,7 +71,7 @@ class TestCase(unittest.TestCase):
         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)"
index 17888a9f286c8f5c89a70b53cfafa8a9ec87f2e3..de4d200374bcea851d6dd0ceb7a1e52f61b1f129 100644 (file)
@@ -21,7 +21,6 @@ import functools
 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 @@ class AssertersMixin(CreatorMixin, DigestMixin, ObjectCheckerMixin):
 
     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 @@ class AssertersMixin(CreatorMixin, DigestMixin, ObjectCheckerMixin):
 
     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().