Visitar URL original
Fix B006 by using an immutable type from the future. · python/importlib_metadata@458fdc3 · GitHub
Skip to content

Commit 458fdc3

Browse files
committed
Fix B006 by using an immutable type from the future.
Ref jaraco/skeleton#210.
1 parent 7b59997 commit 458fdc3

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎tests/compat/py314.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@
55

66
from test.support import warnings_helper as orig
77

8+
if sys.version_info >= (3, 15):
9+
from builtins import frozendict
10+
else:
11+
12+
def frozendict(*args, **kwargs) -> types.MappingProxyType:
13+
"""
14+
Approximate frozendict, added to builtins in Python 3.15.
15+
16+
A mapping proxy is read-only, so as long as the mapping it wraps
17+
has no other referents, it's effectively immutable.
18+
19+
>>> frozendict(a=1)['a']
20+
1
21+
>>> frozendict({'a': 1}) == {'a': 1}
22+
True
23+
"""
24+
return types.MappingProxyType(dict(*args, **kwargs))
25+
826

927
@contextlib.contextmanager
1028
def ignore_warnings(*, category, message=''):

‎tests/test_main.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from . import fixtures
2424
from ._path import Symlink
25+
from .compat.py314 import frozendict
2526

2627

2728
class BasicTests(fixtures.DistInfoPkg, unittest.TestCase):
@@ -134,7 +135,7 @@ def test_unique_distributions(self):
134135

135136
class InvalidMetadataTests(fixtures.OnSysPath, fixtures.SiteDir, unittest.TestCase):
136137
@staticmethod
137-
def make_pkg(name, files=dict(METADATA="VERSION: 1.0")): # noqa: B006
138+
def make_pkg(name, files=frozendict(METADATA="VERSION: 1.0")):
138139
"""
139140
Create metadata for a dist-info package with name and files.
140141
"""

0 commit comments

Comments
 (0)