On Fri, Oct 13, 2017, at 02:30, Nick Coghlan wrote: > Metaclasses currently tend to serve two distinct purposes: > > 1. Actually altering the runtime behaviour of a class and its children > in non-standard ways (e.g. enums, ABCs, ORMs) > 2. Boilerplate reduction in class definitions, reducing the amount of > code you need to write as the author of that class > > Nobody has a problem with using metaclasses for the first purpose - > that's what they're for. > > It's the second use case where they're problematic, as the fact that > they're preserved on the class becomes a leaky implementation detail, > and the lack of a JIT in CPython means they can also end up being > expensive from a runtime performance perspective.
What about a metaclass that isn't a metaclass? A metaclass can be any callable and can return any object, e.g. a normal type. def AutoSlotMeta(name, bases, dct, real_metaclass=type): """turn all class variables into slots""" dct['__slots__'] = list(dct) return real_metaclass(name, bases, dct) _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com