@@ -165,23 +165,12 @@ class EntryPoints(tuple):
165
165
166
166
__slots__ = ()
167
167
168
- def __getitem__ (self , name ) -> Union [ EntryPoint , 'EntryPoints' ] :
168
+ def __getitem__ (self , name ): # -> EntryPoint:
169
169
try :
170
- match = next (iter (self .select (name = name )))
171
- return match
170
+ return next (iter (self .select (name = name )))
172
171
except StopIteration :
173
- if name in self .groups :
174
- return self ._group_getitem (name )
175
172
raise KeyError (name )
176
173
177
- def _group_getitem (self , name ):
178
- """
179
- For backward compatability, supply .__getitem__ for groups.
180
- """
181
- msg = "GroupedEntryPoints.__getitem__ is deprecated for groups. Use select."
182
- warnings .warn (msg , DeprecationWarning )
183
- return self .select (group = name )
184
-
185
174
def select (self , ** params ):
186
175
return EntryPoints (ep for ep in self if ep .matches (** params ))
187
176
@@ -193,6 +182,23 @@ def names(self):
193
182
def groups (self ):
194
183
return set (ep .group for ep in self )
195
184
185
+ @classmethod
186
+ def _from_text_for (cls , text , dist ):
187
+ return cls (ep ._for (dist ) for ep in EntryPoint ._from_text (text ))
188
+
189
+
190
+ class LegacyGroupedEntryPoints (EntryPoints ):
191
+ 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
197
+
198
+ msg = "GroupedEntryPoints.__getitem__ is deprecated for groups. Use select."
199
+ warnings .warn (msg , DeprecationWarning )
200
+ return self .select (group = name )
201
+
196
202
def get (self , group , default = None ):
197
203
"""
198
204
For backward compatibility, supply .get
@@ -202,9 +208,10 @@ def get(self, group, default=None):
202
208
is_flake8 or warnings .warn (msg , DeprecationWarning )
203
209
return self .select (group = group ) or default
8000
td>204
210
205
- @classmethod
206
- def _from_text_for (cls , text , dist ):
207
- return cls (ep ._for (dist ) for ep in EntryPoint ._from_text (text ))
211
+ def select (self , ** params ):
212
+ if not params :
213
+ return self
214
+ return super ().select (** params )
208
215
209
216
210
217
class PackagePath (pathlib .PurePosixPath ):
@@ -704,7 +711,7 @@ def entry_points(**params):
704
711
eps = itertools .chain .from_iterable (
705
712
dist .entry_points for dist in unique (distributions ())
706
713
)
707
- return EntryPoints (eps ).select (** params )
714
+ return LegacyGroupedEntryPoints (eps ).select (** params )
708
715
709
716
710
717
def files (distribution_name ):
0 commit comments