Blog: January 2025

The Corruption of Python

I enjoy doing silly things with code - having an idea that makes me chuckle and then figuring out how to make it happen. These are often fun diversions, an exercise in pushing my limits and Python's - but sometimes they turn into proper projects which I release, other people use, and I then need to maintain. As a result, a lot of my projects harbour a dark secret or two, and I've used a lot of techniques to hide them away and protect my users from the troubles they can bring. I'm going to talk about these techniques ...

Read full post

Magical Metaclasses

Continuing on from the previous post about decorators, we should visit metaclasses before we get to the good stuff.

For those who haven't worked with them, metaclasses are essentially invisible decorators for classes.

The metaclass describes how your class is made. You define a base class with a custom metaclass, then every class which inherits from your base class will have the same metaclass.

Whereas a normal class's __init__ method will let you control what happens when your class is instantiated, the __init__ method on a metaclass will let you control what happens when your class is defined ...

Read full post

Monkeypatching Django

I haven't yet posted here about my project nanodjango. If you haven't heard of it yet, it is a package which lets you write Django in a single file. I gave a lightning talk at Djangocon US and have written an introductory blog post over at Lincoln Loop, if you want to find out more from a user's perspective - but here I'm going to talk about how it works.

A couple of years ago I took over yet another project where the previous developers had heard "Flask is easier than Django", and I saw they had ...

Read full post