On 23 July 2018 at 11:31, Jeroen Demeyer J.Demeyer@ugent.be wrote:
On 2018-07-23 12:24, Jeroen Demeyer wrote:
Another solution that nobody has mentioned (as far as I know) is to add additional syntax to the language for that. For example, one could say that (1:3) could be used to construct slice(1, 3) directly. The parentheses are required to avoid confusion with type hints. I'm not a Python language expert, but I don't think that type hints can occur inside parentheses like that.
And this could be extended to tuples (1:3, 2:4) and lists [1:3, 2:4] of slices too.
I thought the reason the proposal got nowhere was because it's pretty simple to define it yourself:
... def __getitem__(self, slice): ... return slice ...
SH = SliceHelper() SH[1::3]
slice(1, None, 3)
Did I miss something significant about why this wasn't sufficient?