[Python-ideas] adding dictionaries

dw+python-ideas at hmmz.org dw+python-ideas at hmmz.org
Mon Jul 28 17:33:06 CEST 2014


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


More information about the Python-ideas mailing list