8000 Add docstrings to the compatibility shim. Give primacy to group looku… · python/importlib_metadata@d6f7c20 · GitHub
[go: up one dir, main page]

Skip to content

Commit d6f7c20

Browse files
committed
Add docstrings to the compatibility shim. Give primacy to group lookup in compatibility shim.
1 parent 9d55a33 commit d6f7c20

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

importlib_metadata/__init__.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,38 @@ def _from_text_for(cls, text, dist):
188188

189189

190190
class LegacyGroupedEntryPoints(EntryPoints):
191+
"""
192+
Compatibility wrapper around EntryPoints to provide
193+
much of the 'dict' interface previously returned by
194+
entry_points.
195+
"""
196+
191197
def __getitem__(self, name) -> Union[EntryPoint, 'EntryPoints']:
192-
try:
193-
return super().__getitem__(name)
194-
except KeyError:
195-
if name not in self.groups:
196-
raise
198+
"""
199+
When accessed by name that matches a group, return the group.
200+
"""
201+
group = self.select(group=name)
202+
if group:
203+
msg = "GroupedEntryPoints.__getitem__ is deprecated for groups. Use select."
204+
warnings.warn(msg, DeprecationWarning, stacklevel=2)
205+
return group
197206

198-
msg = "GroupedEntryPoints.__getitem__ is deprecated for groups. Use select."
199-
warnings.warn(msg, DeprecationWarning)
200-
return self.select(group=name)
207+
return super().__getitem__(name)
201208

202209
def get(self, group, default=None):
203210
"""
204-
For backward compatibility, supply .get
211+
For backward compatibility, supply .get.
205212
"""
206213
is_flake8 = any('flake8' in str(frame) for frame in inspect.stack())
207214
msg = "GroupedEntryPoints.get is deprecated. Use select."
208-
is_flake8 or warnings.warn(msg, DeprecationWarning)
215+
is_flake8 or warnings.warn(msg, DeprecationWarning, stacklevel=2)
209216
return self.select(group=group) or default
210217

211218
def select(self, **params):
219+
"""
220+
Prevent transform to EntryPoints during call to entry_points if
221+
no selection parameters were passed.
222+
"""
212223
if not params:
213224
return self
214225
return super().select(**params)

0 commit comments

Comments
 (0)
0