From a6932a179be10c310eaa668af1b3226fb8354164 Mon Sep 17 00:00:00 2001 From: Arie Bovenberg Date: Fri, 7 Jan 2022 13:22:18 +0100 Subject: [PATCH 1/4] add missing __slots__ to DeprecatedList --- Lib/importlib/metadata/__init__.py | 2 ++ Lib/test/test_importlib/test_metadata_api.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/Lib/importlib/metadata/__init__.py b/Lib/importlib/metadata/__init__.py index d44541fcbfbf42..f1c46b85a7a9a1 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 e16773a7e87ef2..ae566c647d8138 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): + self.assertRaises( + AttributeError, setattr, entry_points()['entries'][0], 'foo', 4 + ) + def test_metadata_for_this_package(self): md = metadata('egginfo-pkg') assert md['author'] == 'Steven Ma' From 8f349af01da73a5f0212ae910fe383c863ca1c36 Mon Sep 17 00:00:00 2001 From: Arie Bovenberg Date: Fri, 7 Jan 2022 13:28:06 +0100 Subject: [PATCH 2/4] add news entry --- .../next/Library/2022-01-07-13-27-53.bpo-46246.CTLx32.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-01-07-13-27-53.bpo-46246.CTLx32.rst 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 00000000000000..48501714394594 --- /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. From f45cb0e2e6d854f33f49f7b22be352955c085d05 Mon Sep 17 00:00:00 2001 From: Arie Bovenberg Date: Fri, 7 Jan 2022 15:35:38 +0100 Subject: [PATCH 3/4] use AssertRaises as context manager Co-authored-by: Alex Waygood --- Lib/test/test_importlib/test_metadata_api.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_importlib/test_metadata_api.py b/Lib/test/test_importlib/test_metadata_api.py index ae566c647d8138..9c3f368d54a57a 100644 --- a/Lib/test/test_importlib/test_metadata_api.py +++ b/Lib/test/test_importlib/test_metadata_api.py @@ -173,9 +173,8 @@ def test_entry_points_groups_get(self): entry_points().get('missing', ()) == () def test_entry_points_allows_no_attributes(self): - self.assertRaises( - AttributeError, setattr, entry_points()['entries'][0], 'foo', 4 - ) + with self.assertRaises(AttributeError): + entry_points()['entries'][0].foo = 4 def test_metadata_for_this_package(self): md = metadata('egginfo-pkg') From 16d66e1de510f53150173039c30726bf21a0958c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 10 Feb 2022 19:24:59 -0500 Subject: [PATCH 4/4] Update test to capture the actual expectation on EntryPoints object and remove deprecated usage. --- Lib/test/test_importlib/test_metadata_api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_importlib/test_metadata_api.py b/Lib/test/test_importlib/test_metadata_api.py index 9c3f368d54a57a..78287c314ced72 100644 --- a/Lib/test/test_importlib/test_metadata_api.py +++ b/Lib/test/test_importlib/test_metadata_api.py @@ -173,8 +173,9 @@ def test_entry_points_groups_get(self): entry_points().get('missing', ()) == () def test_entry_points_allows_no_attributes(self): + ep = entry_points().select(group='entries', name='main') with self.assertRaises(AttributeError): - entry_points()['entries'][0].foo = 4 + ep.foo = 4 def test_metadata_for_this_package(self): md = metadata('egginfo-pkg')