On Sat, Dec 26, 2020 at 06:09:42PM -0800, Brendan Barnwell wrote: > On 2020-12-26 18:00, Steven D'Aprano wrote:
> >I think if we were designing mapping protocols now, that would be an > >excellent idea, but we aren't, we have decades of history from `dict` > >behind us. And protocols from dict use `keys()` and getitem. E.g. > >update. > > What do you mean by "protocols from dict"? What are these protocols? "And protocols from dict use `keys()` and getitem. E.g. update." The dict in-place union assignment operator also uses the same protocol: >>> class A: ... def keys(self): ... return iter('abc') ... def __getitem__(self, key): ... return key.upper() ... >>> d = {} >>> d |= A() >>> d {'a': 'A', 'b': 'B', 'c': 'C'} (Regular union operator does not, it requires an actual dict.) There may be others. I know I have written code that followed the same interface as update, although I don't have it easily at hand. -- Steve _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/PO3EOV3Z6XADC4WIHO2XHQL4COOBLEVQ/ Code of Conduct: http://python.org/psf/codeofconduct/