From 177d5500ea3618c5c699e2ddd6451fa8dccd1261 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 29 Aug 2021 09:56:11 -0400 Subject: [PATCH 1/2] Restore support for EntryPoint access by item. Fixes #348. --- importlib_metadata/__init__.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index f79a437b..73ca91cc 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -125,7 +125,33 @@ def valid(line): return line and not line.startswith('#') -class EntryPoint: +class DeprecatedTuple: + """ + Provide subscript item access for backward compatibility. + + >>> recwarn = getfixture('recwarn') + >>> ep = EntryPoint(name='name', value='value', group='group') + >>> ep[:] + ('name', 'value', 'group') + >>> ep[0] + 'name' + >>> len(recwarn) + 1 + """ + + _warn = functools.partial( + warnings.warn, + "EntryPoint tuple interface is deprecated. Access members by name.", + DeprecationWarning, + stacklevel=pypy_partial(2), + ) + + def __getitem__(self, item): + self._warn() + return self._key()[item] + + +class EntryPoint(DeprecatedTuple): """An entry point as defined by Python packaging conventions. See `the packaging docs on entry points From 315f637bf9eeaecf127be3c009d796075326ac42 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 29 Aug 2021 11:11:01 -0400 Subject: [PATCH 2/2] Update changelog. --- CHANGES.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index d5398ccc..7085ef52 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,15 @@ +v4.8.1 +====== + +* #348: Restored support for ``EntryPoint`` access by item, + deprecating support in the process. Users are advised + to use direct member access instead of item-based access:: + + - ep[0] -> ep.name + - ep[1] -> ep.value + - ep[2] -> ep.group + - ep[:] -> ep.name, ep.value, ep.group + v4.8.0 ======