--- title: "The snake of Theseus - Pablo Galindo Salgado" tags: PyConTW2023, 2023-organize, 2023-共筆 --- # The snake of Theseus - Pablo Galindo Salgado {%hackmd H6-2BguNT8iE7ZUrnoG1Tg %} <iframe src=https://app.sli.do/event/mL8DEitekbiDDizsDDF2HM height=450 width=100%></iframe> > Collaborative writing start from below > 從這裡開始共筆 > [Slido](https://app.sli.do/event/mL8DEitekbiDDizsDDF2HM/live/questions?clusterId=eu1) :::success [TOC] ::: This talk is about what makes python feel like python. ## 01 - [the ship of theseus](https://en.wikipedia.org/wiki/Ship_of_Theseus) > philosophy dilemma: If you replace all part of this ship, it is still the same ship? > ![Python 歷年Code行數](https://raw.githubusercontent.com/erikbern/git-of-theseus/master/pics/git-git.png) > Source: https://github.com/erikbern/git-of-theseus as we changed python as we remove or add up things (code survive over time) we don't changed things (it's the same ship) python is really written by a lot of people,... the things become more complicated. Python is changed quite quickly. Python is actually does not exist. (radio waves metaphor. You can not see the pink color on the spectrum. It's combanation of different photons) different people have different ideas ### Python only exists in our mind lives in minds ## 02 - The Grammar who says what is python and what is not - it's grammar (rule_names example) metagrammar: grammars describe grammars describe what is python (expanded rules) [LL1-grammar](https://zh.wikipedia.org/zh-tw/LL%E5%89%96%E6%9E%90%E5%99%A8) simple and restrict idomtic simple to write, coded in LL1 [reference:Full Grammar specification](https://docs.python.org/3/reference/grammar.html) 1. Left to right parses input from left to right 2. Leftmost derivation 3. 1 Token Lookahead Biggest restriciton 4. Grammar restriction (break example) is something continue could be a simple statement? (ambiguous rules) ### ars est quelare artem it's importment that when you creating things do not get in the middle (if you write after a grammar, it's ambiguous/complicated) - nonterminal in the grammar... - to make it run in liner memoization.. - context in grammars 1st python 1990 #### PEG parsers have infinite backtracking https://peps.python.org/pep-0617/ ## 03 A New Garmmar World in python sometimes we are introducing new keywords(ideas) hard keywords: can not be used as varibles soft keywords: contextual, some words can be used as variables(e.g. await, async in py3.4, 3.5), backward compatible (e.g the use of underscore) pep636 structure ### only possible with the new peg parser Python 3.10 release note: - This new syntax uses the non LL(1) capacities of the new parser. Check PEP 617 for more details. [PEP 617 – New PEG parser for CPython](https://peps.python.org/pep-0617/) ## 04 The Storm of Tpying the two main topics + static typing + is used by tools analysing the source code without excuting it (e.g. [mypy](https://www.mypy-lang.org/)) + Dynamic typing + is examine at runtime to produce some effects (e.g. [Pydantic](https://docs.pydantic.dev/latest/)) ### Did you know this? + [PEP 484](https://peps.python.org/pep-0484/) + Introduced the typing lang with syntax, annotations, the typing module and other infrastructure. + [PEP 563](https://peps.python.org/pep-0563/) + Introduced `from __future__ import annotations` + [PEP 649](https://peps.python.org/pep-0649/) + Expands the effect of `from __future__ import annotations` ### how users see annotations - small projects and education - enterprise and large projects [PEP 649](https://peps.python.org/pep-0649/) is accepted for Python 3.12 ## 05 battling the GIL - OCT.7 2021 - NOGIL Python targeting 3.11 - JAN 9 2023 - [PEP 703](https://peps.python.org/pep-0703/) - tentatively accepted for Python 3.13 - July 28 2024 ### Challenges of nogic 1. maintanance: increase the Python team's maintenance bourden 2. compatibility: isses for C extensions 3. performance NOGIL 4. packaging: for a while packages might need to be released in two versions (as GIL and NOGIL), which complicates releases and testing too 20 ### Types of programs I/O bounded code: doesn't quite benefit from NOGIL CPU bounded code: does benefit from NOGIL if there's parallelism Mixed workload ### Timeline of adoption 01 0-3 years : experimental builds 02 3-5 years : suppported builds 03 5+ years : NOGIL is the only build of Python ### Challengs for c extensions global state debugging is harder implicit gil as lock interoperabitpality looking infrastructure validation ### The Snake of Theseus pablogsal@gmail.com @pyblogsal 1. what is the biggest difference it has to be something 2. as a thought experiment 3. can you share us one mistake you've made as a CPython change from [] to main . would you consider . how would you suggest for 4. how to consolidate everyone's understanding of python fantastic question, it's hard . what's the hardest Below is the part that speaker updated the talk/tutorial after speech 講者於演講後有更新或勘誤投影片的部份