Skip to content

Commit 0bbdb4e

Browse files
authored
gh-141510: Replace MappingProxyType with frozendict (#144904)
1 parent 16ccdbc commit 0bbdb4e

File tree

5 files changed

+8
-12
lines changed

5 files changed

+8
-12
lines changed

Lib/dataclasses.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ class _KW_ONLY_TYPE:
191191
KW_ONLY = _KW_ONLY_TYPE()
192192

193193
# Since most per-field metadata will be unused, create an empty
194-
# read-only proxy that can be shared among all fields.
195-
_EMPTY_METADATA = types.MappingProxyType({})
194+
# read-only dictionary that can be shared among all fields.
195+
_EMPTY_METADATA = frozendict()
196196

197197
# Markers for the various kinds of fields and pseudo-fields.
198198
class _FIELD_BASE:

Lib/email/headerregistry.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
This module provides an implementation of the HeaderRegistry API.
44
The implementation is designed to flexibly follow RFC5322 rules.
55
"""
6-
from types import MappingProxyType
7-
86
from email import utils
97
from email import errors
108
from email import _header_value_parser as parser
@@ -462,7 +460,7 @@ def init(self, *args, **kw):
462460

463461
@property
464462
def params(self):
465-
return MappingProxyType(self._params)
463+
return frozendict(self._params)
466464

467465

468466
class ContentTypeHeader(ParameterizedMIMEHeader):

Lib/test/support/hashlib_helper.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import unittest
77
import unittest.mock
88
from test.support import import_helper
9-
from types import MappingProxyType
109

1110

1211
def _parse_fullname(fullname, *, strict=False):
@@ -351,7 +350,7 @@ def __init__(
351350
)
352351

353352

354-
_HASHINFO_DATABASE = MappingProxyType({
353+
_HASHINFO_DATABASE = frozendict({
355354
_HashId.md5: _HashInfo(
356355
_HashId.md5,
357356
"_md5.MD5Type",
@@ -500,7 +499,7 @@ def _iter_hash_func_info(excluded):
500499
# keyed hash function. However, as it's exposed by HACL*, we test it.
501500
_HMACINFO_DATABASE[_HashId.blake2s] = _HashInfoItem('_hmac.compute_blake2s_32')
502501
_HMACINFO_DATABASE[_HashId.blake2b] = _HashInfoItem('_hmac.compute_blake2b_32')
503-
_HMACINFO_DATABASE = MappingProxyType(_HMACINFO_DATABASE)
502+
_HMACINFO_DATABASE = frozendict(_HMACINFO_DATABASE)
504503
assert _HMACINFO_DATABASE.keys() == CANONICAL_DIGEST_NAMES
505504

506505

Lib/test/test_dataclasses/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_field_repr(self):
7171
expected_output = "Field(name='id',type=None," \
7272
f"default=1,default_factory={MISSING!r}," \
7373
"init=True,repr=False,hash=None," \
74-
"compare=True,metadata=mappingproxy({})," \
74+
"compare=True,metadata=frozendict()," \
7575
f"kw_only={MISSING!r}," \
7676
"doc='Docstring'," \
7777
"_field_type=None)"

Lib/test/test_hmac.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import hmac
2222
import hashlib
2323
import random
24-
import types
2524
import unittest
2625
import warnings
2726
from _operator import _compare_digest as operator_compare_digest
@@ -303,7 +302,7 @@ def assert_hmac_new_by_name(
303302

304303
def check_hmac_new(
305304
self, key, msg, hexdigest, hashname, digest_size, block_size,
306-
hmac_new_func, hmac_new_kwds=types.MappingProxyType({}),
305+
hmac_new_func, hmac_new_kwds=frozendict(),
307306
):
308307
"""Check that HMAC(key, msg) == digest.
309308
@@ -349,7 +348,7 @@ def assert_hmac_hexdigest_by_name(
349348

350349
def check_hmac_hexdigest(
351350
self, key, msg, hexdigest, digest_size,
352-
hmac_digest_func, hmac_digest_kwds=types.MappingProxyType({}),
351+
hmac_digest_func, hmac_digest_kwds=frozendict(),
353352
):
354353
"""Check and return a HMAC digest computed by hmac_digest_func().
355354

0 commit comments

Comments
 (0)