[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] Call for prudence about PEP-572


> ...
> As to why you might want to use := in a function call, I could imagine
> writing
>     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...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180707/a6299c32/attachment.html>