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/

53b37e14a09c5a718a39fda61fe1b8e5?s=128

PyCon 2019

May 04, 2019
Tweet

Transcript

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

    2019 @di_codes
  2. HI, I'M DUSTIN @di_codes

  3. PEP 572 @di_codes

  4. PYTHON GOVERNANCE @di_codes

  5. BDFL BENEVOLENT DICTATOR FOR LIFE @di_codes

  6. None
  7. PEP PYTHON ENHANCEMENT PROPOSAL @di_codes

  8. None
  9. PEP 8 STYLE GUIDE FOR PYTHON CODE @di_codes

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

    ROSSUM @di_codes
  11. PEP 20 THE ZEN OF PYTHON @di_codes

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

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

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

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

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

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

  18. BDFL DELEGATES @di_codes

  19. @di_codes

  20. PEP 572 ASSIGNMENT EXPRESSIONS @di_codes

  21. := @di_codes

  22. None
  23. None
  24. EXAMPLES @di_codes

  25. BALANCING LOC AND BIG O() @di_codes

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

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

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

  29. AVOIDING INEFFICIENT COMPREHENSIONS @di_codes

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

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

    ] @di_codes
  32. results = [ y for x in data if (y

    := f(x)) ] @di_codes
  33. UNNECESSARY VARIABLES IN SCOPE @di_codes

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

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

  36. PROCESSING STREAMS IN CHUNKS @di_codes

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

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

  39. WHY? @di_codes

  40. FEWER LINES ARE BETTER @di_codes

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

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

  43. FEWER LINES ARE MORE EFFICIENT? @di_codes

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

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

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

  47. = @di_codes

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

    := (y := (x := 0))) # No @di_codes
  49. a[i] = x # Yes a[i] := x # No

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

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

    (x := 1, 2) # Sets x to 1 @di_codes
  52. total += tax # Yes total +:= tax # No

    @di_codes
  53. +:= @di_codes

  54. None
  55. None
  56. PEP 572 @di_codes

  57. RECEPTION @di_codes

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

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

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

  61. None
  62. None
  63. None
  64. TIM PETERS: "THE CURRENT PROPOSAL WOULD HAVE ALLOWED A MODEST

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

    PEOPLE TEND TO FOCUS ON THAT WITHOUT UNDERSTANDING THE DEEPER SEMANTIC ISSUES." @di_codes
  66. ŁUKASZ LANGA: "DICTATORS SHOULD DICTATE" @di_codes

  67. GUIDO VAN ROSSUM: HAD TO STOP READING THE THREADS SO

    HE WOULDN'T "GO INSANE" @di_codes
  68. None
  69. None
  70. None
  71. None
  72. None
  73. None
  74. None
  75. None
  76. None
  77. None
  78. DICTATORS ARE PEOPLE TOO @di_codes

  79. MAINTAINERS ARE PEOPLE TOO @di_codes

  80. PEOPLE ARE PEOPLE TOO @di_codes

  81. QUESTIONS @di_codes

  82. WHAT DOES THIS MEAN FOR PYTHON? @di_codes

  83. @di_codes

  84. @di_codes

  85. @di_codes

  86. @di_codes

  87. IT'S GOING TO BE OK @di_codes

  88. PEP 8000 PYTHON LANGUAGE GOVERNANCE PROPOSAL OVERVIEW @di_codes

  89. PEP 8001 PYTHON GOVERNANCE VOTING PROCESS @di_codes

  90. PEP 8002 OPEN SOURCE GOVERNANCE SURVEY @di_codes

  91. ▸ 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
  92. VOTE DEC 1ST - 16TH, 2018 @di_codes

  93. None
  94. PEP 8016 STEERING COUNCIL MODEL @di_codes

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

  96. . . . @di_codes

  97. None
  98. None
  99. None
  100. None
  101. Q&A @di_codes

  102. WILL THIS BECOME PART OF PYTHON? @di_codes

  103. IT ALREADY HAS (IN 3.8) @di_codes

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

  105. THEN DON'T WRITE IT! @di_codes

  106. IS GUIDO COMING BACK? @di_codes

  107. TO PYTHON? @di_codes

  108. YES! @di_codes

  109. AS BDFL? @di_codes

  110. NOPE @di_codes

  111. WILL THIS HAPPEN AGAIN? @di_codes

  112. WILL ANOTHER PEP BE THIS CONTROVERSIAL? @di_codes

  113. PROBABLY NOT @di_codes

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

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

  116. None
  117. THANKS! @DI_CODES