2 ms·
> All the walrus gets you is making the x "infect" the surrounding namespace which is surprising. Yes, that's what I intended. I was pointing out that the foo(
by chriswarbo 5y ago
> All the walrus gets you is making the x "infect" the surrounding namespace which is surprising.
Yes, that's what I intended. I was pointing out that the foo(x1 if ...) version does not behave the same as the separate 'x = ...' statements, since it doesn't bind the x/y/z variables.
This is usually an advantage (if we don't need those values for anything else), but for completeness I noted that we could use the walrus to recreate the exact behaviour (keyword arguments can't do it, since they only bind variables inside the function call, which (usually) has no observable difference to using positional arguments). You're right that the walrus's effect on the surrounding namespace is 'surprising', and that's why I would prefer to use separate statements if we really want those names defined (since that's less surprising).