[Python-ideas] adding dictionaries

Guido van Rossum guido at python.org
Mon Jul 28 18:08:49 CEST 2014


In addition, dict(A, **B) is not something you easily stumble upon when
your goal is "merge two dicts"; nor is it even clear that that's what it is
when you read it for the first time.

All signs of too-clever hacks in my book.


On Mon, Jul 28, 2014 at 8:33 AM, <dw+python-ideas at hmmz.org> wrote:

> On Tue, Jul 29, 2014 at 12:59:51AM +1000, Steven D'Aprano wrote:
>
> > > One good reason is that people are still convinced "dict(A, **B)"
> > > makes some kind of sense.
> >
> > Explain please. dict(A, **B) makes perfect sense to me, and it works
> > perfectly too. It's a normal constructor call, using the same syntax
> > as any other function or method call. Are you suggesting that it does
> > not make sense?
>
> It worked in Python 2, but Python 3 added code to explicitly prevent the
> kwargs mechanism from being abused by passing non-string keys.
> Effectively, the only reason it worked was due to a Python 2.x kwargs
> implementation detail.
>
> It took me a while to come to terms with this one too, it was really
> quite a nice hack. But that's all it ever was. The domain of valid keys
> accepted by **kwargs should never have exceeded the range supported by
> the language syntax for declaring keyword arguments.
>
>
> David
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140728/6601f5a6/attachment.html>


More information about the Python-ideas mailing list