Comparisons and sorting of a numeric class....

Chris Angelico rosuav at
Fri Jan 23 18:23:44 CET 2015

On Sat, Jan 24, 2015 at 4:03 AM, Rustom Mody <rustompmody at> wrote:
> The only workaround I have been able to come up with is:
> class B4(IntEnum):
>>         F1 = 0
>>         F2 = ""
>>         F3 = None
>>         T  = 1
> which is not bad; its ridiculous

It's ridiculous because you declared an IntEnum and then started using
non-integer values that boolify to the same value (and don't intify).
If that even works, it's a total hack, and it might stop working in a
future version... for example, it doesn't seem to work on my Python

>>> class B4(IntEnum):
...  F1=0
...  F2=""
...  F3=None
...  T=1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/", line 152, in __new__
    enum_member = __new__(enum_class, *args)
ValueError: invalid literal for int() with base 10: ''

Using Enum instead of IntEnum does work, but it's still hardly a
normal use of an enumeration.


More information about the Python-list mailing list