Christopher wrote: Why not allow slice syntax as an expression everywhere? In reply, Todd wrote: That is a very different discussion, and not directly related to keyword indexes. Would it be possible to start a new email thread to discuss it? I think they are closely related matters, at least in terms of implementation. For details see rest of this message. I hope this helps our understanding, even if it shows difficulties lying ahead. My non-expert understanding is that if
d[a=1:2:3] is allowed by making a minimal change to Python's abstract grammar, then f(a=1:2:3) will also be allowed. (Extra work would be required to forbid it.)
d[::, ::]
f(x=SOMETHING) f[x=SOMETHING]
It is also my non-expert understanding that >>> {0:1:2:3:4:5} would then be equivalent to >>> {slice(0, 1, 2): slice(3, 4, 5)} and further that >>> { :: :: : } would become valid syntax! My non-expert understanding is based on https://docs.python.org/3/library/ast.html#abstract-grammar To me it seems that in for example the AST is constrained by slice = Slice(expr? lower, expr? upper, expr? step) | ExtSlice(slice* dims) | Index(expr value) while in the SOMETHING is an expr, and the AST is constrained by expr = BoolOp(boolop op, expr* values) | NamedExpr(expr target, expr value) | BinOp(expr left, operator op, expr right) | UnaryOp(unaryop op, expr operand) | Lambda(arguments args, expr body) | IfExp(expr test, expr body, expr orelse) | Dict(expr* keys, expr* values) ... | List(expr* elts, expr_context ctx) | Tuple(expr* elts, expr_context ctx If this is correct then adding Slice to the choices for expr would extend the AST to allow slices in keyword indices. And then the rest follows. -- Jonathan