[Python-ideas] PEP 572: Assignment Expressions (post #4)

Chris Angelico rosuav at gmail.com
Fri Apr 13 02:47:17 EDT 2018


On Fri, Apr 13, 2018 at 4:27 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> On 04/12/2018 09:52 PM, Chris Angelico wrote:
>
>> foo := a > b   # does this capture 'a', or 'a > b'?
>> bar := c + d   # 'c' or 'c + d'?
>>
>> I'm open to argument here, but my thinking is that these should
>> capture 'a' and 'c + d'.
>
>
> I think := should act the same as = or there will be plenty of confusion.
> If one wants to capture less then parenthesis can be used to narrow it down:
>
>   (foo := a) > b
>
> Looked at another way -- you already have the value named as 'a', so why
> would you also name it as 'foo'?
>

More likely, 'a' won't be a simple name lookup, but a function call. Consider:

pos = -1
while pos := buffer.find(search_term, pos + 1) >= 0:
    ...

Once find() returns -1, the loop terminates. Should this need to be
parenthesized?

ChrisA


More information about the Python-ideas mailing list