On 13 February 2013 07:13, Tim Delaney <timothy.c.delaney@gmail.com> wrote:
Well, that particular case would work (you'd get a NameError: sys) due to having done an attribute lookup on sys, but the following:

class Color(Enum):
    RED, GREEN, BLUE
    if platfor == 'win32':
        MAGENTA

would create an enum value 'platfor'.

BTW, I've just addressed this in my latest version up on BitBucket. Any usage of an object that is more than just assignment (basically, anything that results in a call of a __dunder__ method on the object) will now mark the name as not an enum value and result in a NameError for an unknown name.

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from enum import Enum
>>> class Color(Enum):
...     RED
...     if unknown_name == 'value':
...         PINK
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in Color
  File ".\enum.py", line 123, in __eq__
    def __eq__(self, other): return self._get(True) == other
  File ".\enum.py", line 98, in _get
    raise NameError(self.key)
NameError: unknown_name

Tim Delaney