Skip to content

Commit

Permalink
bpo-46246: add missing __slots__ to importlib.metadata.DeprecatedList (
Browse files Browse the repository at this point in the history
…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
(cherry picked from commit dd76b3f)

Co-authored-by: Arie Bovenberg <a.c.bovenberg@gmail.com>
  • Loading branch information
miss-islington and ariebovenberg committed Feb 11, 2022
1 parent 14284b0 commit 1124ab6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Lib/importlib/metadata/__init__.py
Expand Up @@ -236,6 +236,8 @@ class DeprecatedList(list):
1
"""

__slots__ = ()

_warn = functools.partial(
warnings.warn,
"EntryPoints list interface is deprecated. Cast to list if needed.",
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_importlib/test_metadata_api.py
Expand Up @@ -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'
Expand Down
@@ -0,0 +1,2 @@
Add missing ``__slots__`` to ``importlib.metadata.DeprecatedList``. Patch by
Arie Bovenberg.

0 comments on commit 1124ab6

Please sign in to comment.