[Python-checkins] bpo-46246: add missing __slots__ to importlib.metadata.DeprecatedList (GH-30452)
miss-islington
webhook-mailer at python.org
Thu Feb 10 19:56:25 EST 2022
https://github.com/python/cpython/commit/dd76b3f7d332dd6eced5cbc2ad2adfc397700b3d
commit: dd76b3f7d332dd6eced5cbc2ad2adfc397700b3d
branch: main
author: Arie Bovenberg <a.c.bovenberg at gmail.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-02-10T16:56:21-08:00
summary:
bpo-46246: add missing __slots__ to importlib.metadata.DeprecatedList (GH-30452)
Confirmed with @jaraco that this indeed needs a fix.
A question that came up while I was digging into the code: I think `SelectableGroups` could similarly use `__slots__ = ()`, since its purpose seems only for convenience around `dict`, not to have attributes of its own.
Automerge-Triggered-By: GH:jaraco
files:
A Misc/NEWS.d/next/Library/2022-01-07-13-27-53.bpo-46246.CTLx32.rst
M Lib/importlib/metadata/__init__.py
M Lib/test/test_importlib/test_metadata_api.py
diff --git a/Lib/importlib/metadata/__init__.py b/Lib/importlib/metadata/__init__.py
index 371c482209586..9fd6e04ae9abf 100644
--- a/Lib/importlib/metadata/__init__.py
+++ b/Lib/importlib/metadata/__init__.py
@@ -278,6 +278,8 @@ class DeprecatedList(list):
1
"""
+ __slots__ = ()
+
_warn = functools.partial(
warnings.warn,
"EntryPoints list interface is deprecated. Cast to list if needed.",
diff --git a/Lib/test/test_importlib/test_metadata_api.py b/Lib/test/test_importlib/test_metadata_api.py
index e16773a7e87ef..78287c314ced7 100644
--- a/Lib/test/test_importlib/test_metadata_api.py
+++ b/Lib/test/test_importlib/test_metadata_api.py
@@ -172,6 +172,11 @@ def test_entry_points_groups_get(self):
entry_points().get('entries', 'default') == entry_points()['entries']
entry_points().get('missing', ()) == ()
+ def test_entry_points_allows_no_attributes(self):
+ ep = entry_points().select(group='entries', name='main')
+ with self.assertRaises(AttributeError):
+ ep.foo = 4
+
def test_metadata_for_this_package(self):
md = metadata('egginfo-pkg')
assert md['author'] == 'Steven Ma'
diff --git a/Misc/NEWS.d/next/Library/2022-01-07-13-27-53.bpo-46246.CTLx32.rst b/Misc/NEWS.d/next/Library/2022-01-07-13-27-53.bpo-46246.CTLx32.rst
new file mode 100644
index 0000000000000..4850171439459
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-01-07-13-27-53.bpo-46246.CTLx32.rst
@@ -0,0 +1,2 @@
+Add missing ``__slots__`` to ``importlib.metadata.DeprecatedList``. Patch by
+Arie Bovenberg.
More information about the Python-checkins
mailing list