
Guido wrote:
I think it’s a reasonable idea and encourage you to start working on a design for the API and then a PRP.
In this post, I explore how the new API might interact with dict objects. (I think PRP is a typo for PEP.) Here is an example of the present behaviour >>> d = dict() >>> d[x=1, y=2] = 3 SyntaxError: invalid syntax with the syntax error occurring at the first '=' symbol. So what should be the new behaviour of: >>> d = dict() >>> d[x=1, y=2] = 3 To me, it is clear that we won't get a syntax error. This is because the proposal implies that >>> d[x=1, y=2] = 3 executes without error, for some values of 'd'. If these two lines >>> d = dict() >>> d[x=1, y=2] = 3 execute without error, then I would the expect >>> len(d) 1 >>> d[x=1, y=2] 3 I would further expect >>> k = list(d.keys())[0] to give an object 'k', with the property >>> d[k] 3 This object 'k' corresponds to the source code fragment x=1, y=2 in d[x=1, y=2] and I would expect 'k' to work as a key in any instance of dict. Here is something that might help the reader. It is that current Python gives >>> d = dict() >>> d['x=1', 'y=2'] = 3 >>> list(d.keys())[0] ('x=1', 'y=2') and we are looking for an analogous object for >>> d[x=1, y=2] = 3 To summarize and slightly extend the above. If >>> d = dict() >>> d[x=1, y=2] = 3 executes without error, then there is an object 'k' such that >>> d[x=1, y=2] = 5 >>> d[k] = 5 are equivalent. (This object 'k' is the key in the collection of (key, value) pairs that are the entries in the dict.) Aside: The key object, if it exists, has a type. Whether this type is a new type or an existing type is an implementation question. This message is focussed on the user experience. To conclude: If d[x=1, y=2] is allowed for 'd' a dict then consistency with the current dict behaviour requires the existence of a key object that corresponds to the fragment 'x=1, y=2'. Finally, I have tried to be both clear and concise. I hope my contribution helps. -- Jonathan