@@ -165,23 +165,12 @@ class EntryPoints(tuple):
165165
166166 __slots__ = ()
167167
168- def __getitem__ (self , name ) -> Union [ EntryPoint , 'EntryPoints' ] :
168+ def __getitem__ (self , name ): # -> EntryPoint:
169169 try :
170- match = next (iter (self .select (name = name )))
171- return match
170+ return next (iter (self .select (name = name )))
172171 except StopIteration :
173- if name in self .groups :
174- return self ._group_getitem (name )
175172 raise KeyError (name )
176173
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-
185174 def select (self , ** params ):
186175 return EntryPoints (ep for ep in self if ep .matches (** params ))
187176
@@ -193,6 +182,23 @@ def names(self):
193182 def groups (self ):
194183 return set (ep .group for ep in self )
195184
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+
196202 def get (self , group , default = None ):
197203 """
198204 For backward compatibility, supply .get
@@ -202,9 +208,10 @@ def get(self, group, default=None):
202208 is_flake8 or warnings .warn (msg , DeprecationWarning )
203209 return self .select (group = group ) or default
204210
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 )
208215
209216
210217class PackagePath (pathlib .PurePosixPath ):
@@ -704,7 +711,7 @@ def entry_points(**params):
704711 eps = itertools .chain .from_iterable (
705712 dist .entry_points for dist in unique (distributions ())
706713 )
707- return EntryPoints (eps ).select (** params )
714+ return LegacyGroupedEntryPoints (eps ).select (** params )
708715
709716
710717def files (distribution_name ):
0 commit comments