On 2020-04-16 04:33, Rob Cliffe via Python-Dev wrote:
Here's another revolutionary thought: add a new operator and associated dunder method (to object?) whose meaning is *undefined*. Its default implementation would do *nothing* useful (raise an error? return None?). E.g. suppose the operator were `..` Then in a specific class you could implement x..y to mean x['y'] and then you could write obj..abc..def..ghi Still fairly concise, but warns that what is happening is not normal attribute lookup.
Interesting, I've thought the same thing. Double dot might be a good option. In practice however I've not encountered key names in JSON that conflict with the dictionary methods. A missing protocol could handle clashes when they happen, as applied to keys. Keys that conflict are simply shadowed by the method names unless you use [''] notation. I know, that answer is not satisfying to the purist. Double dot is better in that regard. Yet haven't found it to be a concrete problem. Perhaps linters could find code using uncalled dict method names as a mitigation. Suppose it boils down to a judgement call in the end. -Mike