]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46246: add missing __slots__ to importlib.metadata.DeprecatedList (GH-30452)
authorArie Bovenberg <a.c.bovenberg@gmail.com>
Fri, 11 Feb 2022 00:56:21 +0000 (01:56 +0100)
committerGitHub <noreply@github.com>
Fri, 11 Feb 2022 00:56:21 +0000 (16:56 -0800)
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
Lib/importlib/metadata/__init__.py
Lib/test/test_importlib/test_metadata_api.py
Misc/NEWS.d/next/Library/2022-01-07-13-27-53.bpo-46246.CTLx32.rst [new file with mode: 0644]

index 371c48220958629799026633e481cdf603144e39..9fd6e04ae9abf19b154de58fc5800fb0812fad8d 100644 (file)
@@ -278,6 +278,8 @@ class DeprecatedList(list):
     1
     """
 
+    __slots__ = ()
+
     _warn = functools.partial(
         warnings.warn,
         "EntryPoints list interface is deprecated. Cast to list if needed.",
index e16773a7e87ef265e4f4a884d23ffb65d242dc55..78287c314ced72586413e1e8145a0d939e391e8e 100644 (file)
@@ -172,6 +172,11 @@ class APITests(
             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 (file)
index 0000000..4850171
--- /dev/null
@@ -0,0 +1,2 @@
+Add missing ``__slots__`` to ``importlib.metadata.DeprecatedList``. Patch by
+Arie Bovenberg.