A while back, I created a Struct class, which allows the creation of C-like structs, but you had to create a subclass of Struct, specify the endianness as a class attribute, and create a __format__ method that built the struct members. A little while ago, I had the thought to wrap it into a decorator, defStruct/defStructLE/defStructBE, that automagickly calls 'type' to build the appropriate Struct class for you, given a method.
So what once was:
class Foo(Struct):
__endian__ = Struct.LE
def __format__(self):
self.foo = Struct.uint32
self.bar = Struct.string(self.foo)
Became: @defStructLE
def Foo(self):
self.foo = Struct.uint32
self.bar = Struct.string(self.foo)
Much, much cleaner, all thanks to the magic of 'type'.