Message193648
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. |
|
Date |
User |
Action |
Args |
2013-07-24 14:01:53 | lambacck | set | recipients:
+ lambacck |
2013-07-24 14:01:53 | lambacck | set | messageid: <1374674513.33.0.493713574743.issue18545@psf.upfronthosting.co.za> |
2013-07-24 14:01:53 | lambacck | link | issue18545 messages |
2013-07-24 14:01:53 | lambacck | create | |
|