You can use the metaclass MetaDocument()as a factory to create a class that replaces your class Documentby reusing the class attributes:
class Document(object):
body = vars(Document).copy()
body.pop('__dict__', None)
body.pop('__weakref__', None)
Document = MetaDocument(Document.__name__, Document.__bases__, body)
This does not require you to build the third argument, the body of the class, manually.
You can turn this into a class decorator:
def with_metaclass(mcls):
def decorator(cls):
body = vars(cls).copy()
body.pop('__dict__', None)
body.pop('__weakref__', None)
return mcls(cls.__name__, cls.__bases__, body)
return decorator
then use as:
@with_metaclass(MetaDocument)
class Document(object):
six library :
@six.add_metaclass(MetaDocument)
class Document(object):
@six.add_metaclass() decorator __slots__, , , ; .
six six.with_metaclass() factory:
class Document(six.with_metaclass(MetaDocument)):
MRO.