2 ms·
No-go on metaclass, the received type for metaclass __new__ method's members argument is a plain dict. Unless this is changed in Py 3, I still don't understand
by marmaduke 13y ago
No-go on metaclass, the received type for metaclass __new__ method's members argument is a plain dict.
Unless this is changed in Py 3, I still don't understand how this works.
- saidajigumi 13y agoHere's an example from the Python 3 docs[1] that specifically uses metaclass for exactly this scenario: class OrderedClass(type): @classmethod def __prepare__(metacls, name, bases, **kwds): return collections.OrderedDict() def __new__(cls, name, bases, namespace, **kwds): result = type.__new__(cls, name, bases, dict(namespace)) result.members = tuple(namespace) return result class A(metaclass=OrderedClass): def one(self): pass def two(self): pass def three(self): pass def four(self): pass >>> A.members ('__module__', 'one', 'two', 'three', 'four') [1] http://docs.python.org/3/reference/datamodel.html#metaclass-example http://docs.python.org/3/reference/datamodel.html#metaclass-...