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. AUSTIN PYTHON MEETUP
    AUGUST 2018

    View full-size slide

  2. HI, I'M DUSTIN

    View full-size slide

  3. PYTHON GOVERNANCE

    View full-size slide

  4. BDFL
    BENEVOLENT DICTATOR
    FOR LIFE

    View full-size slide

  5. PEP
    PYTHON ENHANCEMENT PROPOSAL

    View full-size slide

  6. PEP 8
    STYLE GUIDE FOR PYTHON CODE

    View full-size slide

  7. PEP 8
    STYLE GUIDE FOR PYTHON CODE
    AUTHOR: GUIDO VAN ROSSUM

    View full-size slide

  8. PEP 20
    THE ZEN OF PYTHON

    View full-size slide

  9. PEP 20
    THE ZEN OF PYTHON
    AUTHOR: TIM PETERS

    View full-size slide

  10. PEP 566
    METADATA FOR PYTHON SOFTWARE
    PACKAGES 2.1

    View full-size slide

  11. PEP 566
    METADATA FOR PYTHON SOFTWARE
    PACKAGES 2.1
    AUTHOR: DUSTIN INGRAM

    View full-size slide

  12. BDFL
    DELEGATES

    View full-size slide

  13. 1) DRAFT
    2) ACCEPTANCE
    3) IMPLEMENTATION

    View full-size slide

  14. match = pattern.search(data)
    if match is not None:
    do_something(match)

    View full-size slide

  15. chunk = file.read(8192)
    while chunk:
    process(chunk)
    chunk = file.read(8192)

    View full-size slide

  16. foo = [f(x), f(x)**2, f(x)**3]

    View full-size slide

  17. y = f(x)
    foo = [y, y**2, y**3]

    View full-size slide

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

    View full-size slide

  19. filtered_data = [
    f(x) for x in data
    if f(x) is not None
    ]

    View full-size slide

  20. match = pattern.search(data)
    if match is not None:
    do_something(match)

    View full-size slide

  21. if (match := pattern.search(data)) is not None:
    do_something(match)

    View full-size slide

  22. chunk = file.read(8192)
    while chunk:
    process(chunk)
    chunk = file.read(8192)

    View full-size slide

  23. while chunk := file.read(8192):
    process(chunk)

    View full-size slide

  24. foo = [f(x), f(x)**2, f(x)**3]

    View full-size slide

  25. foo = [y := f(x), y**2, y**3]

    View full-size slide

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

    View full-size slide

  27. filtered_data = [
    f(x) for x in data
    if f(x) is not None
    ]

    View full-size slide

  28. filtered_data = [
    y for x in data
    if (y := f(x)) is not None
    ]

    View full-size slide

  29. LESS LINES
    ARE BETTER

    View full-size slide

  30. foo = [y := f(x), y**2, y**3]

    View full-size slide

  31. y = f(x)
    foo = [y, y**2, y**3]

    View full-size slide

  32. LESS LINES
    ARE MORE EFFICIENT?

    View full-size slide

  33. match = re.match(data)
    group = match.group(1) if match else None

    View full-size slide

  34. group = re.match(data).group(1) if re.match(data) else None

    View full-size slide

  35. group = match.group(1) if (match := re.match(data)) else None

    View full-size slide

  36. foo = 'foo'
    if (foo := 'bar') is not None:
    do_something(...)
    print(foo)

    View full-size slide

  37. if any((comment := line).startswith('#') for line in lines):
    print("First comment:", comment)
    else:
    print("There are no comments")

    View full-size slide

  38. if all((nonblank := line).strip() == '' for line in lines):
    print("All lines are blank")
    else:
    print("First non-blank line:", nonblank)

    View full-size slide

  39. total = 0
    partial_sums = [total := total + v for v in values]
    print("Total:", total)

    View full-size slide

  40. x = y = z = 0 # Yes
    (z := (y := (x := 0))) # No

    View full-size slide

  41. a[i] = x # Yes
    a[i] := x # No
    self.rest = [] # Yes
    self.rest := [] # No

    View full-size slide

  42. x = 1, 2 # Sets x to (1, 2)
    (x := 1, 2) # Sets x to 1

    View full-size slide

  43. total += tax # Yes
    total +:= tax # No

    View full-size slide

  44. BACKWARDS
    COMPATIBILITY
    "WHERE WILL THIS WORK?"

    View full-size slide

  45. TEACHABILITY
    "WHAT DO WE CALL THIS?"

    View full-size slide

  46. ATTRACTIVENESS
    "IT'S JUST UGLY!"

    View full-size slide

  47. TIM PETERS:
    "THE CURRENT PROPOSAL WOULD
    HAVE ALLOWED A MODEST BUT
    CLEAR IMPROVEMENT IN QUITE A
    FEW BITS OF CODE."

    View full-size slide

  48. BARRY WARSAW:
    "SINCE IT CHANGES THE SYNTAX OF
    THE LANGUAGE, PEOPLE TEND TO
    FOCUS ON THAT WITHOUT
    UNDERSTANDING THE DEEPER
    SEMANTIC ISSUES."

    View full-size slide

  49. ŁUKASZ LANGA:
    "DICTATORS SHOULD DICTATE"

    View full-size slide

  50. GUIDO VAN ROSSUM:
    HAD TO STOP READING THE THREADS
    SO HE WOULDN'T "GO INSANE"

    View full-size slide

  51. WHAT DOES THIS
    MEAN FOR PYTHON?

    View full-size slide

  52. IT'S GOING
    TO BE OK

    View full-size slide

  53. WILL THIS BECOME
    PART OF PYTHON?

    View full-size slide

  54. PROBABLY
    (IN 3.8)

    View full-size slide

  55. BUT I DON'T LIKE IT!

    View full-size slide

  56. THEN DON'T
    WRITE IT!

    View full-size slide

  57. IS GUIDO
    COMING BACK?

    View full-size slide

  58. PROBABLY NOT

    View full-size slide

  59. WILL THIS
    HAPPEN AGAIN?

    View full-size slide

  60. PROBABLY NOT

    View full-size slide

  61. ¯\_(ϑ)_/¯

    View full-size slide