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
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/MO6MGS3ZHGGTGLODFY7BAC5WGXZZYJ3R/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to