News for hackers. Stuff that matters.
Re:PEP 435 Accepted – Adding an Enum type to the Python stan... by saidajigumi on Friday May 10, 2013 @02:37PM (#5687889)
There's no need to modify the interpreter. Redefining __dict__ to support ordering would be enough, or perhaps defining a purpose-built __metaclass__[1].

[1] http://stackoverflow.com/a/6581949/183481

Re:PEP 435 Accepted – Adding an Enum type to the Python stan... by marmaduke on Friday May 10, 2013 @03:05PM (#5688052)
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.

Re:PEP 435 Accepted – Adding an Enum type to the Python stan... by saidajigumi on Friday May 10, 2013 @04:39PM (#5688552)
Here'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-...