Skip to content

Instantly share code, notes, and snippets.

@plombardi89
Created June 18, 2013 15:49
Show Gist options
  • Save plombardi89/5806511 to your computer and use it in GitHub Desktop.
Save plombardi89/5806511 to your computer and use it in GitHub Desktop.
Attempting to create a mixin function that can mixin multiple classes
# I get an error like the following with this object:
# metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
def mixin(TargetClass, *args, **kwargs):
if kwargs.get('name') is None:
kwargs['name'] = '%s_mixed_with_%s' % (TargetClass.__name__, "".join(map(str, args)))
class MixedClass(TargetClass, *args):
pass
MixedClass.__name__ = kwargs.get('name')
return MixedClass
# assume for all intensive puposes that Foo, Bar, Baz, Bot, Quux, and Muck are Classes
def uber_foo = mixin(Foo, Bar, Baz, Bot, Quux, Muck, name="UberFoo")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment