this /static/media/twitter/N9RV8L.png

I have a GitHub repository that contains a compilation of all the awful code I've written over the years, abusing features like metaclasses, decorators, various dunder methods, and the mutable nature of Python's underlying data structures.

It's a funny way to see how Python works under the hood, but it's also educational.

Really!

Each of the tricks is entertainingly terrible. But they're also mostly self-contained ways to see what happens when you override certain behaviours of the Python language. Anyone with an intermediate level of Python understanding should be able to follow along and learn something.

I will cover:

  • Replacing an imported module with a class, so attribute lookups can be @properties, with hilarious results.
  • Overriding the __sub__ magic method to create a hyphenated, fuzzy-matching version of a boolean.
  • Using __getattr__ to save time implementing all the functions in the math module.
  • Using __eq__ to make things that aren't really the same look the same.

This talk is an entertaining tour of the Python Data Model, and the things you can do - if you're so inclined.

Mark Smith

Affiliation: MongoDB

Mark has been a developer since the mid-90s, these days specialising in Python & Rust. He's built everything from online games to medical imaging software & travel sites. When he's not sitting at his computer keyboard, you'll probably find him soldering a new one from scratch. He lives in Edinburgh with his wife, daughter, dog and cat.