Created
June 18, 2013 15:49
-
-
Save plombardi89/5806511 to your computer and use it in GitHub Desktop.
Attempting to create a mixin function that can mixin multiple classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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