Last Updated: February 25, 2016
·
445
· demianbrecht

metaclass & abc hackery

While playing around with metaclasses and investigating abc's implementations, I came up with a proof of concept that is abc-like in nature, but doesn't rely on inheritance. Basically, it allows you to say you want one object to /look/ like another one without /being/ one.

Nasty code really (and there are a couple problems with it that I'm aware of with it as-is) and I'd highly suggest not using it for /anything/. But it was fun to play with anyway :)

https://gist.github.com/demianbrecht/6944269

Check out the unit tests at the bottom to see it in action. If anyone knows of any magic methods in the data model that allow you to do the same as setattr on an instance on the class object, I'd love to know as it would eliminate the need for the late_bind function.

Enjoy the Bad Thing I have done!