Skip to content

Instantly share code, notes, and snippets.

@mplanchard
Created January 23, 2018 14:35
Show Gist options
  • Save mplanchard/a3e5fa11e8825d33f47b8892dc1c17cf to your computer and use it in GitHub Desktop.
Save mplanchard/a3e5fa11e8825d33f47b8892dc1c17cf to your computer and use it in GitHub Desktop.
Python 2/3 Compatible Metaclasses Without Third Party Dependencies
"""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