@@ -204,7 +204,100 @@ def matches(self, **params):
204
204
return all (map (operator .eq , params .values (), attrs ))
205
205
206
206
207
- class EntryPoints (tuple ):
207
+ class DeprecatedList (list ):
208
+ """
209
+ Allow an otherwise immutable object to implement mutability
210
+ for compatibility.
211
+
212
+ >>> recwarn = getfixture('recwarn')
213
+ >>> dl = DeprecatedList(range(3))
214
+ >>> dl[0] = 1
215
+ >>> dl.append(3)
216
+ >>> del dl[3]
217
+ >>> dl.reverse()
218
+ >>> dl.sort()
219
+ >>> dl.extend([4])
220
+ >>> dl.pop(-1)
221
+ 4
222
+ >>> dl.remove(1)
223
+ >>> dl += [5]
224
+ >>> dl + [6]
225
+ [1, 2, 5, 6]
226
+ >>> dl + (6,)
227
+ [1, 2, 5, 6]
228
+ >>> dl.insert(0, 0)
229
+ >>> dl
230
+ [0, 1, 2, 5]
231
+ >>> dl == [0, 1, 2, 5]
232
+ True
233
+ >>> dl == (0, 1, 2, 5)
234
+ True
235
+ >>> len(recwarn)
236
+ 1
237
+ """
238
+
239
+ _warn = functools .partial (
240
+ warnings .warn ,
241
+ "EntryPoints list interface is deprecated. Cast to list if needed." ,
242
+ DeprecationWarning ,
243
+ stacklevel = 2 ,
244
+ )
245
+
246
+ def __setitem__ (self , * args , ** kwargs ):
247
+ self ._warn ()
248
+ return super ().__setitem__ (* args , ** kwargs )
249
+
250
+ def __delitem__ (self , * args , ** kwargs ):
251
+ self ._warn ()
252
+ return super ().__delitem__ (* args , ** kwargs )
253
+
254
+ def append (self , * args , ** kwargs ):
255
+ self ._warn ()
256
+ return super ().append (* args , ** kwargs )
257
+
258
+ def reverse (self , * args , ** kwargs ):
259
+ self ._warn ()
260
+ return super ().reverse (* args , ** kwargs )
261
+
262
+ def extend (self , * args , ** kwargs ):
263
+ self ._warn ()
264
+ return super ().extend (* args , ** kwargs )
265
+
266
+ def pop (self , * args , ** kwargs ):
267
+ self ._warn ()
268
+ return super ().pop (* args , ** kwargs )
269
+
270
+ def remove (self , * args , ** kwargs ):
271
+ self ._warn ()
272
+ return super ().remove (* args , ** kwargs )
273
+
274
+ def __iadd__ (self , * args , ** kwargs ):
275
+ self ._warn ()
276
+ return super ().__iadd__ (* args , ** kwargs )
277
+
278
+ def __add__ (self , other ):
279
+ if not isinstance (other , tuple ):
280
+ self ._warn ()
281
+ other = tuple (other )
282
+ return self .__class__ (tuple (self ) + other )
283
+
284
+ def insert (self , * args , ** kwargs ):
285
+ self ._warn ()
286
+ return super ().insert (* args , ** kwargs )
287
+
288
+ def sort (self , * args , ** kwargs ):
289
+ self ._warn ()
290
+ return super ().sort (* args , ** kwargs )
291
+
292
+ def __eq__ (self , other ):
293
+ if not isinstance (other , tuple ):
294
+ self ._warn ()
295
+ other = tuple (other )
296
+
297
+ return tuple (self ).__eq__ (other )
298
+
299
+
300
+ class EntryPoints (DeprecatedList ):
208
301
"""
209
302
An immutable collection of selectable EntryPoint objects.
210
303
"""
@@ -215,6 +308,14 @@ def __getitem__(self, name): # -> EntryPoint:
215
308
"""
216
309
Get the EntryPoint in self matching name.
217
310
"""
311
+ if isinstance (name , int ):
312
+ warnings .warn (
313
+ "Accessing entry points by index is deprecated. "
314
+ "Cast to tuple if needed." ,
315
+ DeprecationWarning ,
316
+ stacklevel = 2 ,
317
+ )
318
+ return super ().__getitem__ (name )
218
319
try :
219
320
return next (iter (self .select (name = name )))
220
321
except StopIteration :
0 commit comments