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

Dustin Ingram - PEP 572: The Walrus Operator

Dustin Ingram - PEP 572: The Walrus Operator

In this talk, we'll learn about a highly controversial change to Python syntax, the rationale for it, and the fallout as the result of it.

Along the way we'll go in-depth on how new ideas about Python are proposed, discussed, and become part of the language, what's unique about Python's process compared to other open source projects, and recent developments and what they mean for the future of the wider Python community.

https://us.pycon.org/2019/schedule/presentation/195/

PyCon 2019

May 04, 2019
Tweet

More Decks by PyCon 2019

Other Decks in Programming

Transcript

  1. PEP 572
    THE WALRUS OPERATOR
    ~
    DUSTIN INGRAM
    PYCON US 2019
    @di_codes

    View full-size slide

  2. HI, I'M DUSTIN
    @di_codes

    View full-size slide

  3. PEP 572
    @di_codes

    View full-size slide

  4. PYTHON
    GOVERNANCE
    @di_codes

    View full-size slide

  5. BDFL
    BENEVOLENT DICTATOR
    FOR LIFE
    @di_codes

    View full-size slide

  6. PEP
    PYTHON ENHANCEMENT
    PROPOSAL
    @di_codes

    View full-size slide

  7. PEP 8
    STYLE GUIDE
    FOR PYTHON CODE
    @di_codes

    View full-size slide

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

    View full-size slide

  9. PEP 20
    THE ZEN OF PYTHON
    @di_codes

    View full-size slide

  10. PEP 20
    THE ZEN OF PYTHON
    AUTHOR: TIM PETERS
    @di_codes

    View full-size slide

  11. PEP 566
    METADATA FOR PYTHON
    SOFTWARE PACKAGES 2.1
    @di_codes

    View full-size slide

  12. PEP 566
    METADATA FOR PYTHON
    SOFTWARE PACKAGES 2.1
    AUTHOR: DUSTIN INGRAM
    @di_codes

    View full-size slide

  13. 1) DRAFT
    2) ACCEPTANCE
    3) IMPLEMENTATION
    @di_codes

    View full-size slide

  14. 1) DRAFT
    2) ACCEPTANCE
    3) IMPLEMENTATION
    @di_codes

    View full-size slide

  15. 1) DRAFT
    2) ACCEPTANCE
    3) IMPLEMENTATION
    @di_codes

    View full-size slide

  16. BDFL
    DELEGATES
    @di_codes

    View full-size slide

  17. PEP 572
    ASSIGNMENT EXPRESSIONS
    @di_codes

    View full-size slide

  18. EXAMPLES
    @di_codes

    View full-size slide

  19. BALANCING
    LOC AND BIG O()
    @di_codes

    View full-size slide

  20. foo = [f(x), f(x)**2, f(x)**3]
    @di_codes

    View full-size slide

  21. y = f(x)
    foo = [y, y**2, y**3]
    @di_codes

    View full-size slide

  22. foo = [y := f(x), y**2, y**3]
    @di_codes

    View full-size slide

  23. AVOIDING
    INEFFICIENT
    COMPREHENSIONS
    @di_codes

    View full-size slide

  24. results = []
    for x in data:
    result = f(x)
    if result:
    results.append(result)
    @di_codes

    View full-size slide

  25. results = [
    f(x) for x in data
    if f(x)
    ]
    @di_codes

    View full-size slide

  26. results = [
    y for x in data
    if (y := f(x))
    ]
    @di_codes

    View full-size slide

  27. UNNECESSARY
    VARIABLES IN SCOPE
    @di_codes

    View full-size slide

  28. match = pattern.search(data)
    if match:
    do_something(match)
    @di_codes

    View full-size slide

  29. if (match := pattern.search(data)):
    do_something(match)
    @di_codes

    View full-size slide

  30. PROCESSING
    STREAMS IN CHUNKS
    @di_codes

    View full-size slide

  31. chunk = file.read(8192)
    while chunk:
    process(chunk)
    chunk = file.read(8192)
    @di_codes

    View full-size slide

  32. while chunk := file.read(8192):
    process(chunk)
    @di_codes

    View full-size slide

  33. WHY?
    @di_codes

    View full-size slide

  34. FEWER LINES
    ARE BETTER
    @di_codes

    View full-size slide

  35. y = f(x)
    foo = [y, y**2, y**3]
    @di_codes

    View full-size slide

  36. foo = [y := f(x), y**2, y**3]
    @di_codes

    View full-size slide

  37. FEWER LINES
    ARE MORE EFFICIENT?
    @di_codes

    View full-size slide

  38. match = re.match(data)
    group = match.group(1) if match else None
    @di_codes

    View full-size slide

  39. group = re.match(data).group(1) if re.match(data) else None
    @di_codes

    View full-size slide

  40. group = match.group(1) if (match := re.match(data)) else None
    @di_codes

    View full-size slide

  41. x = y = z = 0 # Yes
    (z := (y := (x := 0))) # No
    @di_codes

    View full-size slide

  42. a[i] = x # Yes
    a[i] := x # No
    @di_codes

    View full-size slide

  43. self.rest = [] # Yes
    self.rest := [] # No
    @di_codes

    View full-size slide

  44. x = 1, 2 # Sets x to (1, 2)
    (x := 1, 2) # Sets x to 1
    @di_codes

    View full-size slide

  45. total += tax # Yes
    total +:= tax # No
    @di_codes

    View full-size slide

  46. +:=
    @di_codes

    View full-size slide

  47. PEP 572
    @di_codes

    View full-size slide

  48. RECEPTION
    @di_codes

    View full-size slide

  49. BACKWARDS
    COMPATIBILITY
    "WHERE WILL THIS WORK?"
    @di_codes

    View full-size slide

  50. TEACHABILITY
    "WHAT DO WE CALL THIS?"
    @di_codes

    View full-size slide

  51. ATTRACTIVENESS
    "IT'S JUST UGLY!"
    @di_codes

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  54. ŁUKASZ LANGA:
    "DICTATORS SHOULD DICTATE"
    @di_codes

    View full-size slide

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

    View full-size slide

  56. DICTATORS
    ARE PEOPLE TOO
    @di_codes

    View full-size slide

  57. MAINTAINERS
    ARE PEOPLE TOO
    @di_codes

    View full-size slide

  58. PEOPLE
    ARE PEOPLE TOO
    @di_codes

    View full-size slide

  59. QUESTIONS
    @di_codes

    View full-size slide

  60. WHAT DOES THIS
    MEAN FOR PYTHON?
    @di_codes

    View full-size slide

  61. IT'S GOING
    TO BE OK
    @di_codes

    View full-size slide

  62. PEP 8000
    PYTHON LANGUAGE
    GOVERNANCE PROPOSAL OVERVIEW
    @di_codes

    View full-size slide

  63. PEP 8001
    PYTHON GOVERNANCE
    VOTING PROCESS
    @di_codes

    View full-size slide

  64. PEP 8002
    OPEN SOURCE
    GOVERNANCE SURVEY
    @di_codes

    View full-size slide

  65. ▸ PEP 8010 - The Technical Leader Governance Model
    ▸ PEP 8011 - Python Governance Model Lead by Trio of Pythonistas
    ▸ PEP 8012 - The Community Governance Model
    ▸ PEP 8013 - The External Governance Model
    ▸ PEP 8014 - The Commons Governance Model
    ▸ PEP 8015 - Organization of the Python community
    ▸ PEP 8016 - The Steering Council Model
    @di_codes

    View full-size slide

  66. VOTE
    DEC 1ST - 16TH, 2018
    @di_codes

    View full-size slide

  67. PEP 8016
    STEERING COUNCIL MODEL
    @di_codes

    View full-size slide

  68. VOTE
    JAN 21ST - FEB 4TH, 2019
    @di_codes

    View full-size slide

  69. . . .
    @di_codes

    View full-size slide

  70. Q&A
    @di_codes

    View full-size slide

  71. WILL THIS BECOME
    PART OF PYTHON?
    @di_codes

    View full-size slide

  72. IT ALREADY HAS
    (IN 3.8)
    @di_codes

    View full-size slide

  73. BUT I DON'T LIKE IT!
    @di_codes

    View full-size slide

  74. THEN DON'T
    WRITE IT!
    @di_codes

    View full-size slide

  75. IS GUIDO
    COMING BACK?
    @di_codes

    View full-size slide

  76. TO PYTHON?
    @di_codes

    View full-size slide

  77. YES!
    @di_codes

    View full-size slide

  78. AS BDFL?
    @di_codes

    View full-size slide

  79. NOPE
    @di_codes

    View full-size slide

  80. WILL THIS
    HAPPEN AGAIN?
    @di_codes

    View full-size slide

  81. WILL ANOTHER PEP
    BE THIS CONTROVERSIAL?
    @di_codes

    View full-size slide

  82. PROBABLY NOT
    @di_codes

    View full-size slide

  83. WILL PEOPLE BE
    NEGATIVE
    ON THE INTERNET?
    @di_codes

    View full-size slide

  84. ¯\_(ϑ)_/¯
    @di_codes

    View full-size slide

  85. THANKS!
    @DI_CODES

    View full-size slide