Hacking the Python AST

Suhas SG (~jargnar)


25

Votes

Description:

Summary

Computer languages are a remarkable feat of human scientific engineering. In this talk, we'll look at the innards of Python, and specifically learn how to modify Abstract Syntax Trees (for world peace).

Rough agenda

  • [ 05 mins ] --- A brief intro to languages and compilers
  • [ 05 mins ] --- CPython
  • [ 10 mins ] --- Everything about Python ASTs
  • [ 15 mins ] --- Let's write a flake8 plugin (to understand ASTs better)
  • [ 05 mins ] --- Metaprogramming, code as data, possibilities and more!

What we'll learn

  • We'll learn the life of a python code, and how the CPython process works.
  • We'll understand and be able to participate in conversations that include words like LL(1) parser
  • We'll make our devious minds work towards hacking into source code and modifying it with the help of ast.NodeTransformer
  • We'll learn to write a Flake8 plugin
  • A treasure map to dive into deeper waters

Prerequisites:

  • Basics of Python, must be comfortable with lists, functions, classes
  • Basic idea / understanding of data structures
  • A mischievous mind to get hands dirty for intercepting source code and parsing ASTs
  • A bottle of water to keep yourself hydrated

Content URLs:

  • Teaser video: https://youtu.be/Lvy_DcZnYOE
  • Github repo: https://github.com/jargnar/hacking-python

Speaker Info:

Suhas is a data scientist, a speaker, and a design hacker from Bangalore, India. He has designed and built big data solutions for some of the Fortune 500 companies with Gramener.

He runs the Bangalore chapter of Internet Society, dealing with Internet-related, social and policy issues, in addition to running a data visualization and art museum called LifeWithData.

Section: Core Python
Type: Talks
Target Audience: Advanced
Last Updated:

I'm looking forward to this. Good job @jargnar

Sumith (~Sumith1896)

I'm not able to attend PyCon this year. I'm gone through your proposal i feel its quite interesting to me. I study and execute the example you gave in the proposal. I have a few questions:

1) I need few real time examples and real time scenarios. 2) Where can i implement this ast module ?

seenureddy (~seenureddy)
The comment is marked as spam.

adepterp

I'm waiting for this with great impatience. I try to read more about that on different resources. And I think that is really great job!

brandonturner

I'm waiting for this with great impatience. I try to read more about that on different resources. And I think that is really great job!

brandonturner

Login to add a new comment.