Skip to content

Commit

Permalink
Restore support for EntryPoint access by item. Fixes #348.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Aug 29, 2021
1 parent fa620f1 commit 177d550
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion importlib_metadata/__init__.py
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 177d550

Please sign in to comment.