
Jonathan and all! Thanks for picking up on this thread, I almost given up hope that anyone would be interested. Then it suddenly blew up :)! Jonathan, your suggestion makes sense as a stop-gap measure for current Python, but I'm unclear on the way forward to the new syntax: When you say we introduce a new syntax where:
value = d[K(1, 2, 3, a=4, b=5)] d[K(1, 2, 3, a=4, b=5)] = value
becomes:
value = d[1, 2, 3, a=4, b=5] d[1, 2, 3, a=4, b=5] = value
somehow the interpreter would need to know that the intent is to create an instance of 'K'. How is that association expressed? Or is the idea that - the same was as slices - there would be a predefined object within the language that is always the thing that gets created in these instances? It appears to me that the current behavior is: d[32] becomes d.__getitem__(32) d[2,4,"boo"] becomes d.__getitem__( (2,4,"boo") ) d[2:3:"boo"] becomes d.__getitem__( slice(2,3,"boo") ) So then maybe d[2,4,scare="boo"] could become d.__getitem__( {0:2, 1:4, "scare":"boo"} )? That is of course quite a bit different from the args, kwargs syntax, but I don't think it's invalid as positional arguments would get an integer key while keyword arguments would get a string key. With this change, of course your previous (current python) syntax would make K into a function as opposed to a class: def K(*args, **kwargs): ret_val = {} for idx, value in enumerate(args): ret_val[idx] = value for key, value in kwargs.items(): assert isinstance(key, str) ret_val[key] = value return ret_val
value = d[K(1, 2, 3, a=4, b=5)] d[K(1, 2, 3, a=4, b=5)] = value
Thanks again, Andras