Skip to content

Commit

Permalink
Merge pull request #349 from python/348-entrypoint-tuple-compat
Browse files Browse the repository at this point in the history
Restore support for EntryPoint access by item.
  • Loading branch information
jaraco committed Aug 29, 2021
2 parents fa620f1 + 315f637 commit 7a3130a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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
======

Expand Down
28 changes: 27 additions & 1 deletion importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7a3130a

Please sign in to comment.