[Python-Dev] The new and improved PEP 572, same great taste with 75% less complexity! (original) (raw)

Chris Angelico rosuav at gmail.com
Wed Apr 25 19:42:58 EDT 2018


On Thu, Apr 26, 2018 at 9:05 AM, Victor Stinner <vstinner at redhat.com> wrote:

# Handle a matched regex if (match := pattern.search(data)) is not None: ...

# A more explicit alternative to the 2-arg form of iter() invocation while (value := readnextitem()) is not None: ... # Share a subexpression between a comprehension filter clause and its output filtereddata = [y for x in data if (y := f(x)) is not None] What do you think of adding the variant without the new ":=" syntax? It would help to see the benefit of the new ":=" syntax, and help to compare the two syntaxes. if: if (match := pattern.search(data)) is not None: ... vs match = pattern.search(data) if match is not None: ... while: while (value := readnextitem()) is not None: ... vs while True: value = readnextitem() if value is None: break ... list-comprehension: filtereddata = [y for x in data if (y := f(x)) is not None] vs filtereddata = [f(x) for x in data] filtereddata = [x for x in filtereddata if x is not None]

Doing that for everything would put the PEP solidly into "TL;DR" territory, I'm afraid. There's already too much verbiage in some of those sections.

Plus, we'd get right back into debates about how if you just change your intended semantics slightly, there's a completely different way to achieve something actually quite different, and we've already been around that a few times already.

ChrisA



More information about the Python-Dev mailing list