Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PEP 572: The Walrus Operator

PEP 572: The Walrus Operator

A discussion on Python Governance, an introduction to PEP 572 and the walrus operator, as well as the resulting fallout.

Dustin Ingram

August 08, 2018
Tweet

More Decks by Dustin Ingram

Other Decks in Technology

Transcript

  1. :=

  2. results = [] for x in data: result = f(x)

    if result is not None: results.append(result)
  3. results = [] for x in data: result = f(x)

    if result is not None: results.append(result)
  4. foo = 'foo' if (foo := 'bar') is not None:

    do_something(...) print(foo)
  5. if all((nonblank := line).strip() == '' for line in lines):

    print("All lines are blank") else: print("First non-blank line:", nonblank)
  6. total = 0 partial_sums = [total := total + v

    for v in values] print("Total:", total)
  7. =

  8. x = y = z = 0 # Yes (z

    := (y := (x := 0))) # No
  9. a[i] = x # Yes a[i] := x # No

    self.rest = [] # Yes self.rest := [] # No
  10. x = 1, 2 # Sets x to (1, 2)

    (x := 1, 2) # Sets x to 1
  11. TIM PETERS: "THE CURRENT PROPOSAL WOULD HAVE ALLOWED A MODEST

    BUT CLEAR IMPROVEMENT IN QUITE A FEW BITS OF CODE."
  12. BARRY WARSAW: "SINCE IT CHANGES THE SYNTAX OF THE LANGUAGE,

    PEOPLE TEND TO FOCUS ON THAT WITHOUT UNDERSTANDING THE DEEPER SEMANTIC ISSUES."