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.

8db101b3a812b0464c53e5409c12ea94?s=128

Dustin Ingram

August 08, 2018
Tweet

Transcript

  1. 3.
  2. 6.
  3. 16.
  4. 17.

    :=

  5. 18.
  6. 19.
  7. 20.
  8. 25.

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

    if result is not None: results.append(result)
  9. 27.
  10. 34.

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

    if result is not None: results.append(result)
  11. 36.
  12. 37.
  13. 45.
  14. 46.

    foo = 'foo' if (foo := 'bar') is not None:

    do_something(...) print(foo)
  15. 49.

    if all((nonblank := line).strip() == '' for line in lines):

    print("All lines are blank") else: print("First non-blank line:", nonblank)
  16. 50.

    total = 0 partial_sums = [total := total + v

    for v in values] print("Total:", total)
  17. 51.

    =

  18. 52.

    x = y = z = 0 # Yes (z

    := (y := (x := 0))) # No
  19. 53.

    a[i] = x # Yes a[i] := x # No

    self.rest = [] # Yes self.rest := [] # No
  20. 54.

    x = 1, 2 # Sets x to (1, 2)

    (x := 1, 2) # Sets x to 1
  21. 56.
  22. 57.
  23. 58.
  24. 62.
  25. 63.
  26. 64.
  27. 65.
  28. 66.

    TIM PETERS: "THE CURRENT PROPOSAL WOULD HAVE ALLOWED A MODEST

    BUT CLEAR IMPROVEMENT IN QUITE A FEW BITS OF CODE."
  29. 67.

    BARRY WARSAW: "SINCE IT CHANGES THE SYNTAX OF THE LANGUAGE,

    PEOPLE TEND TO FOCUS ON THAT WITHOUT UNDERSTANDING THE DEEPER SEMANTIC ISSUES."
  30. 70.
  31. 71.
  32. 72.
  33. 84.