On Tue, 5 Mar 2019 16:39:40 +0900 INADA Naoki <[email protected]> wrote: > I think some people in favor of PEP 584 just want > single expression for merging dicts without in-place update. > > But I feel it's abuse of operator overload. I think functions > and methods are better than operator unless the operator > has good math metaphor, or very frequently used as concatenate > strings. > > This is why function and methods are better: > > * Easy to search. > * Name can describe it's behavior better than abused operator. > * Simpler lookup behavior. (e.g. subclass and __iadd__) > > Then, I propose `dict.merge` method. It is outer-place version > of `dict.update`, but accepts multiple dicts. (dict.update() > can be updated to accept multiple dicts, but it's not out of scope). > > * d = d1.merge(d2) # d = d1.copy(); d.update(d2)
One should also be able to write `d = dict.merge(d1, d2, ...)` If dict merging is important enough to get a new spelling, then I think this proposal is the best: explicit, unambiguous, immediately understandable and easy to remember. Regards Antoine. _______________________________________________ Python-ideas mailing list [email protected] https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
