On Thu, Aug 12, 2021 at 09:57:06AM -0400, Ricky Teachey wrote:
This got me thinking just now: allowing ellipses instead of None for the first two arguments of the slice() constructor might be a neat idea.
Like this?
obj = slice(..., ..., 5) print(obj) slice(Ellipsis, Ellipsis, 5)
The arguments to slice can be anything you like.
slice({'a': object()}, int, ('spam', 'eggs')) slice({'a': <object object at 0x7f0067ed9420>}, <class 'int'>, ('spam', 'eggs'))
and the interpretation is entirely up to the class:
class C: ... def __getitem__(self, obj): ... return obj ... C()["Hello world!":[]:2.5j] slice('Hello world!', [], 2.5j)
Aside from the use of a literal `...` for Ellipsis, which is a lot more recent, this behaviour goes back to Python 1.5 or older. Slices have always been liberal about what they accept. -- Steve