On 8 Oct 2019, at 20:49, Todd <toddrjen@gmail.com> wrote:

On Tue, Oct 8, 2019 at 2:18 PM Anders Hovmöller <boxed@killingar.net> wrote:

On 8 Oct 2019, at 20:07, Todd <toddrjen@gmail.com> wrote:

On Tue, Oct 8, 2019 at 1:30 PM Anders Hovmöller <boxed@killingar.net> wrote:

On 8 Oct 2019, at 19:19, Caleb Donovick <donovick@cs.stanford.edu> wrote:


>>> dict(foo=:1)
  File "<string>", line 1
SyntaxError: invalid syntax

I don't see how that's an argument, we are talking about a syntax extension.   Slice builder syntax is only every allowed in a subscript.  Edit my original grammar change proposal to:

subscriptlist: ... | kwargsubscript (','  kwargsubscript )* [',']
kwargsubscript: NAME '=' subscript

Now slices are allowed in keyword arguments.

I wasn't making an argument, I was wondering what exactly we are even discussing. It seems like people are inventing new syntax willy nilly in this thread and I am getting very confused :)

/ Anders 

I thought we were talking about allowing __getitem__ to support keywords.  I assumed the keywords would use the same syntax as positional values, and converting colons to slice objects is part of that syntax.  So this isn't new syntax, it is just making the positional and keyword syntaxes the same.

I don't see it. Can you give examples of all the variations of slicing and their keyword equivalent so I understand what you mean? I'll write out the slicing variants and you can fill in how it would look with keyword arguments:


The colon operation would be converted to slices identically to how it is with positional arguments, it is just that those slices would assigned to values in a dict (or some other mapping) instead of values in a tuple.  Otherwise it would work exactly the same.

x[:] is x[slice(None, None)]
x[foo=:] is x[foo=slice(None, None)]

x[a:] is x[slice(a, None)]
x[foo=a:] is x[foo=slice(a, None)]

x[-a:] is x[slice(-a, None)]
x[foo=-a:] is x[foo=slice(-a, None)]

x[a:b] is x[slice(a, b)]
x[foo=a:b] is x[foo=slice(a, b)]

x[-a:b] is x[slice(-a, b)]
x[foo=-a:b] is x[foo=slice(-a, b)]

x[a:-b] is x[slice(a, -b)]
x[foo=a:-b] is x[foo=slice(a, -b)]

x[-a:-b] is x[slice(-a, -b)]
x[foo=-a:-b] is x[foo=slice(-a, -b)]

x[:b] is x[slice(None, b)]
x[foo=:b] is x[foo=slice(None, b)]

x[:-b] is x[slice(None, -b)]
x[foo=:-b] is x[foo=slice(None, -b)]

If you look at multiple indices,

x[a, -b:c] is x[a, slice(-b, c)]
x[foo=a, bar=-b:c] is x[foo=a, bar=slice(-b, c)

Aaaah. Now I see it. Thanks for clarifying that for me.