Crimes with the Python syntax

Tushar Sadhwani (~tushar29)




Over the past few years digging into Python's runtime and language features, I've often run into some weird, obscure parts of the language. Very weird and obscure parts.

Such as imports being hackable enough to directly import JSON files. Or being able to change the syntax of the language, _at runtime_.

And I'd note them down. All the weird, esoteric, not-to-be-named features of the language. And eventually, I'd find some way to abuse that feature. Do something heinous. Write code that would make any code reviewer question my sanity. _Committing crimes_, with the Python syntax.

This talk is an explainer of all these features, and why you should never use them. Unless, of course, you need to.


  • Introduction (2 minutes)
  • The convoluted Python import machinery (5 minutes)
  • Frame-hacking, and the sys._getframe() API. (5 minutes)
  • Tracers, debuggers, and editing your code at runtime. (5 minutes)
  • Creating our own mini language inside Python, at runtime. (5 minutes)
  • Abusing the Python startup machinery to run arbitrary code. (3 minutes)
  • The end, and questionnaire. (5 minutes)


Having a basic understanding of Python's runtime would be helpful.

The talk will go through code examples that assume you know Python's data structures (lists, dicts etc.) and the standard library sufficiently well.

Speaker Info:

Long-term Python developer, author, OSS contributor and speaker, Tushar currently works as a Software Engineer building language tools at DeepSource.

When not working, he tries to contribute to the Python developer tools ecosystem, like black, ruff, flake8 and mypy.

Speaker Links:

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