From f4f788e0fb851049ddbdbeecd1cdbdf9367dd3c8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 13 Aug 2021 14:27:16 -0400 Subject: [PATCH 1/3] Add test capturing failure. Ref #337. --- tests/test_api.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_api.py b/tests/test_api.py index 6bf25b3c..04f04544 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -180,6 +180,10 @@ def test_entry_points_groups_get(self): entry_points().get('entries', 'default') == entry_points()['entries'] entry_points().get('missing', ()) == () + def test_entry_point_as_dict(self): + ep = entry_points(group='entries')['main'] + assert ep._asdict() == dict(name='main', group='entries', value='mod:main') + def test_metadata_for_this_package(self): md = metadata('egginfo-pkg') assert md['author'] == 'Steven Ma' From 7b42ca1dc05f01c0ebd9c744379eb92ff4bd817f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 13 Aug 2021 14:33:54 -0400 Subject: [PATCH 2/3] Override _asdict. Fixes #337. --- importlib_metadata/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index 9f5bf347..d87ff082 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -209,6 +209,10 @@ def matches(self, **params): attrs = (getattr(self, param) for param in params) return all(map(operator.eq, params.values(), attrs)) + def _asdict(self): + # override _asdict, broken by custom __iter__. + return {key: getattr(self, key) for key in self._fields} + class DeprecatedList(list): """ From 3c543a6b7ca141815d8144a227c05196c9395420 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 13 Aug 2021 14:35:20 -0400 Subject: [PATCH 3/3] Update changelog. Ref #337. --- CHANGES.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 7d3227c8..3c49c847 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,9 @@ +v4.7.0 +====== + +* #337: ``EntryPoint`` objects now implement ``namedtuple._asdict`` + to fulfill interface expecation of namedtuple objects. + v4.6.4 ======