Over the weekend, I wanted to implement something that acted as both a class and
function decorator, but could also be used as a context manager. I needed this
flexibility for overriding configuration values making it easier to write tests.
I wanted to use it in the following ways:
as a function decorator:
as a class decorator that would decorate all methods that start with
as a context manager that allowed for multiple layer of overriding:
This kind of need comes up periodically, but infrequently enough that I forget
how I wrote it the last time around.
This post walks through how I structured it.