Skip to content

Commit 7a3130a

Browse files
authored
Merge pull request #349 from python/348-entrypoint-tuple-compat
Restore support for EntryPoint access by item.
2 parents fa620f1 + 315f637 commit 7a3130a

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

CHANGES.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
v4.8.1
2+
======
3+
4+
* #348: Restored support for ``EntryPoint`` access by item,
5+
deprecating support in the process. Users are advised
6+
to use direct member access instead of item-based access::
7+
8+
- ep[0] -> ep.name
9+
- ep[1] -> ep.value
10+
- ep[2] -> ep.group
11+
- ep[:] -> ep.name, ep.value, ep.group
12+
113
v4.8.0
214
======
315

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy