Created
September 27, 2018 20:48
-
-
Save pikhovkin/26162b7903fd03f56948319940dbd187 to your computer and use it in GitHub Desktop.
Metaclass resolver
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
def metaclass_resolver(*classes, **options): | |
"""Metaclass resolver | |
Example: | |
SomeClass(metaclass_resolver(ClassMixin, BaseClass, SomeActionClass, some_field1=True, some_field2=42)): | |
pass | |
:param classes: | |
:param options: | |
:return: | |
""" | |
metaclass = tuple({t for t in set(map(type, classes)) if t.__name__ != 'type'}) | |
if len(metaclass) == 1: | |
metaclass = metaclass[0] | |
else: | |
metaclass = type('_'.join(meta_cls.__name__ for meta_cls in metaclass), metaclass, options) | |
return metaclass('_'.join(cls.__name__ for cls in classes), classes, options) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment