
On Sat, Apr 18, 2020 at 12:19:30PM -0400, David Mertz wrote:
On Sat, Apr 18, 2020, 8:15 AM Alex Hall <alex.mojaki@gmail.com> wrote:
Under your proposal, these two programs are both valid syntax with different meanings:
(1)
f(**{u, v})
(2)
x = {u, v}
f(**x)
I don't understand what the meaning of (2) would be. Currently it is a TypeError... Is that "valid" because it's not a syntax error?!
Yes, as Andrew pointed out, it is valid syntax: it isn't rejected by the compiler, it generates byte-code, and then when you run it, it has behaves differently from (1). So it has a meaning: "raise TypeError in an inefficient fashion". Not *useful* meaning, to be sure, but still meaning. I think a fundamental point is that `**{identifier}` looks like you are applying `**` unpacking to a set, but you actually aren't, it is a special syntactic form. If that disturbs you, I'm not going to say you are wrong. I'm a little sad about it myself, I just don't give it a very high weighting since we already have plenty of other similar cases: func(a, b, c) # Not a tuple. import a, b, c # Also not a tuple. del a, b, c # Still not a tuple. mapping[key] # And not a single-item list either :-) I think I would be more concerned by this if I wanted this keyword argument shortcut to work everywhere, not just in function calls. E.g. mydict = **{a, b c} # like {'a': a, 'b': b, 'c': c} but I don't care much about that. -- Steven