This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lambacck
Recipients lambacck
Date 2013-07-24.14:01:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1374674513.33.0.493713574743.issue18545@psf.upfronthosting.co.za>
In-reply-to
Content
Starting at line 153 in enum.py there is:

   153             if not use_args:
   154                 enum_member = __new__(enum_class)
   155                 original_value = value
   156             else:
   157                 enum_member = __new__(enum_class, *args)
   158                 original_value = member_type(*args)
   159             if not hasattr(enum_member, '_value_'):
   160                 enum_member._value_ = original_value

When use_args is True, the member_type is always called with the arguments even if the return value from enum_member has a _value_ attr. If the __new__ function transforms the the *args then the call to member_type(*args) can fail even thought the value would not be used. I've attached a patch with a fix and a test to demonstrate the problem.

The use case for the test in the attached patch is to populate Django ORM choices to a field. The first value in the tuple is the value used in the database (and as the Enum value) and the second value in the tuple is the label that Django shows in select boxes.
History
Date User Action Args
2013-07-24 14:01:53lambaccksetrecipients: + lambacck
2013-07-24 14:01:53lambaccksetmessageid: <1374674513.33.0.493713574743.issue18545@psf.upfronthosting.co.za>
2013-07-24 14:01:53lambaccklinkissue18545 messages
2013-07-24 14:01:53lambacckcreate