Falsey Enums

Ben Finney ben+python at benfinney.id.au
Fri Jul 28 04:13:57 EDT 2017


Ethan Furman <ethan at stoneleaf.us> writes:

> class X(Enum):
>     Falsey = 0
>     Truthy = 1
>     Fakey = 2
>     def __bool__(self):
>         return bool(self.value)

I am surprised this is not already the behaviour of an Enum class,
without overriding the ‘__bool__’ method.

What would be a good reason not to have this behaviour by default for
‘Enum.__bool__’? (i.e. if this were reported as a bug on the ‘enum.Enum’
implementation, what would be good reasons not to fix it?)

-- 
 \     “As scarce as truth is, the supply has always been in excess of |
  `\                                       the demand.” —Josh Billings |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list