~/talk

Practical Python parsing with the ast standard module

Talkat PyCon Italia 2025 · 2025-05-28..05-31· [compilers-and-language-design]
links:none on file
slides:none on file

Shows how to use the standard ast library to parse Python code with ast.parse and inspect nodes via ast.walk and NodeVisitor/NodeTransformer. Demonstrates a live run over the pydantic codebase to collect per-function metrics (line count, character count) and plots correlation, finds instances where dataclasses are applied via calls not names, and rewrites list comprehensions into set comprehensions. Also covers helpers like ast.get_source_segment, ast.get_docstring and ast.unparse for regenerating modified code.

AI-written summary · about

  1. 0:00Introduction to ast
  2. 1:07Why use the ast module
  3. 3:11Getting the AST from code
  4. 4:56Understanding AST nodes
  5. 8:27Common AST node types
  6. 10:55Traversing the AST
  7. 14:26Node visitors and transformers
  8. 17:59Other AST helpers
  9. 18:39Demo overview
  10. 19:00Analyzing a codebase
  11. 20:45Visualizing function stats
  12. 21:25Checking for dataclasses
  13. 22:50When to use ast
  14. 23:32Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.