On Thu, Apr 26, 2018 at 9:05 AM, Victor Stinner <vstin...@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 := read_next_item()) is not None: >> ... >> >> # Share a subexpression between a comprehension filter clause and its >> output >> filtered_data = [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 := read_next_item()) is not None: ... > vs > while True: > value = read_next_item() > if value is None: break > ... > > list-comprehension: > filtered_data = [y for x in data if (y := f(x)) is not None] > vs > filtered_data = [f(x) for x in data] > filtered_data = [x for x in filtered_data 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 _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com