Created
January 23, 2018 14:35
-
-
Save mplanchard/a3e5fa11e8825d33f47b8892dc1c17cf to your computer and use it in GitHub Desktop.
Python 2/3 Compatible Metaclasses Without Third Party Dependencies
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
"""This example uses the ABCMeta class as its exemplar metaclass.""" | |
from abc import ABCMeta | |
# Create an instance of the metaclass. We can define __slots__ to be | |
# an empty tuple, because we don't need this class to store any attributes. | |
# This instance can be used multiple times, imported, etc., as desired. | |
ABC = ABCMeta('ABC', (object,), {'__slots__': ()}) | |
class MyAbstractClass(ABC): | |
"""This is now a 2/3 compatible metaclass.""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment