[Python-Dev] (name := expression) doesn't fit the narrative of PEP 20

Chris Angelico rosuav at gmail.com
Sat Apr 28 07:37:22 EDT 2018


On Sat, Apr 28, 2018 at 9:18 PM, Ned Batchelder <ned at nedbatchelder.com> wrote:
> It's entirely true that binding expressions don't change this situation at
> all, EXCEPT that the entire point of binding expressions is to be able to
> express in one statement what used to take more than one.  With binding
> expressions, actions may be coverage-hidden within one statement that
> without them would have been coverage-visible in more than one statement.

So far, all the examples in the PEP have the exact same coverage with
and without assignment expressions, with a few exceptions where
coverage is *improved* by them (where the alternative is to duplicate
a function call). By combining multiple lines into one, we also ensure
that all of it is executed exactly once, instead of having conditional
execution.

ChrisA


More information about the Python-Dev mailing list