Skip to content

Commit 177d550

Browse files
committed
Restore support for EntryPoint access by item. Fixes #348.
1 parent fa620f1 commit 177d550

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

importlib_metadata/__init__.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,33 @@ def valid(line):
125125
return line and not line.startswith('#')
126126

127127

128-
class EntryPoint:
128+
class DeprecatedTuple:
129+
"""
130+
Provide subscript item access for backward compatibility.
131+
132+
>>> recwarn = getfixture('recwarn')
133+
>>> ep = EntryPoint(name='name', value='value', group='group')
134+
>>> ep[:]
135+
('name', 'value', 'group')
136+
>>> ep[0]
137+
'name'
138+
>>> len(recwarn)
139+
1
140+
"""
141+
142+
_warn = functools.partial(
143+
warnings.warn,
144+
"EntryPoint tuple interface is deprecated. Access members by name.",
145+
DeprecationWarning,
146+
stacklevel=pypy_partial(2),
147+
)
148+
149+
def __getitem__(self, item):
150+
self._warn()
151+
return self._key()[item]
152+
153+
154+
class EntryPoint(DeprecatedTuple):
129155
"""An entry point as defined by Python packaging conventions.
130156
131157
See `the packaging docs on entry points

0 commit comments

Comments
 (0)