Created
October 6, 2015 08:36
-
-
Save mjhennig/22a16f34b9d3317c06c7 to your computer and use it in GitHub Desktop.
Metaclasses in Python 2 and 3
This file contains hidden or 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 with_metaclass(metaclass, *bases): | |
| """ | |
| Resembles functions six.with_metaclass() and flask.with_metaclass(). | |
| """ | |
| constructor = lambda c, name, b, dct: metaclass(name, bases, dct) | |
| intermediate = type('__metaclass__', (type,), {'__new__': constructor}) | |
| return type.__new__(intermediate, '__class__', (object,), {}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment