On Fri, Apr 16, 2010 at 9:04 AM, Hagen Fürstenau <ha...@zhuliguan.net> wrote: >> This behavior seems pretty strange to me, indeed PyPy gives the >> TypeError for both attempts. I just wanted to confirm that it was in >> fact intentional. > > Oleg already answered why f(**{1:3}) raises a TypeError. But your > question seems to be rather why dict(**{1:3}) doesn't. > > For functions implemented in Python, non-string arguments are always > rejected, but C functions (like the dict constructor) don't have to > reject them. I don't see any benefit in allowing them, but it's probably > not worth breaking code by disallowing them either.
"dict(x, **y)" as an expression version of x.update(y) seems to be fairly well known[1], so disallowing non-string keyword arguments seems likely to break existing code, as well as (probably?) harming performance. So I can't see CPython changing here. I'm not sure whether other implementations should be required to follow suit, though---maybe this should be regarded as an implementation-defined detail? Mark [1] http://stackoverflow.com/questions/38987/how-can-i-merge-two-python-dictionaries-as-a-single-expression ) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com