[Python-Dev] Call for prudence about PEP-572
tim.peters at gmail.com
Sat Jul 7 12:53:14 EDT 2018
> As to why you might want to use := in a function call, I could imagine
> if validate(name := re.search(pattern, line).group(1)):
> return name
When I was staring at my code, I never mentioned the very first plausible
use I bumped into (in code I was actively working on at the time):
while not probable_prime(p := randrange(lo, hi)):
# and now `p` is likely a random prime in range
I never mentioned it because I expected it would annoy people on 3(!)
- assigning in a function call
- reducing the loop body to `pass`
- using the binding long after the loop ended
Indeed, for those reasons it wasn't "an obvious" win to me - or an obvious
loss. So I just moved on.
However, after staring at hundreds of other cases, it does strike me as "a
small win" today - my brain cells have rewired to recognize more ":="
patterns at a glance.
Whether that's a good thing or not I don't know, but it is a real thing ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev