Re: Falsey Enums

2017-07-29 Thread Pavol Lisy
On 7/28/17, Steve D'Aprano wrote: > On Fri, 28 Jul 2017 05:52 pm, Ethan Furman wrote: > >> class X(Enum): >> Falsey = 0 >> Truthy = 1 >> Fakey = 2 >> def __bool__(self): >> return bool(self.value) > > Thanks Ethan. BTW bool at enum seems

Re: Falsey Enums

2017-07-28 Thread Ethan Furman
On 07/28/2017 01:13 AM, Ben Finney wrote: Ethan Furman 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.

Re: Falsey Enums

2017-07-28 Thread Chris Angelico
On Fri, Jul 28, 2017 at 8:28 PM, Steve D'Aprano wrote: > On Fri, 28 Jul 2017 05:52 pm, Ethan Furman wrote: > >> class X(Enum): >> Falsey = 0 >> Truthy = 1 >> Fakey = 2 >> def __bool__(self): >> return bool(self.value) > > Thanks Ethan. > >

Re: Falsey Enums

2017-07-28 Thread Steve D'Aprano
On Fri, 28 Jul 2017 05:52 pm, Ethan Furman wrote: > class X(Enum): > Falsey = 0 > Truthy = 1 > Fakey = 2 > def __bool__(self): > return bool(self.value) Thanks Ethan. Like Ben, I'm surprised that's not the default behaviour. -- Steve “Cheer up,” they said,

Re: Falsey Enums

2017-07-28 Thread Rustom Mody
On Friday, July 28, 2017 at 1:45:46 PM UTC+5:30, Ben Finney wrote: > Ethan Furman 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

Re: Falsey Enums

2017-07-28 Thread Ben Finney
Ethan Furman 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

Re: Falsey Enums

2017-07-28 Thread Ethan Furman
On 07/27/2017 07:15 PM, Steve D'Aprano wrote: I has some Enums: from enum import Enum class X(Enum): Falsey = 0 Truthy = 1 Fakey = 2 and I want bool(X.Falsey) to be False, and the others to be True. What should I do? class X(Enum): Falsey = 0 Truthy = 1 Fakey = 2

Re: Falsey Enums

2017-07-28 Thread Paul Rubin
Dan Sommers writes: > def __bool__(self): > return False if self == X.Falsey else True return self != X.Falsey -- https://mail.python.org/mailman/listinfo/python-list

Re: Falsey Enums

2017-07-27 Thread Dan Sommers
On Fri, 28 Jul 2017 12:15:20 +1000, Steve D'Aprano wrote: > I has some Enums: > > from enum import Enum > class X(Enum): > Falsey = 0 > Truthy = 1 > Fakey = 2 > > > and I want bool(X.Falsey) to be False, and the others to be True. What should > I > do? Add the following to your

Falsey Enums

2017-07-27 Thread Rustom Mody
Isn't dunder-bool what you want? (dunder-nonzero in python2) Dunno if special caveats for Enums PS sorry for phone-post -- I've broken my leg -- https://mail.python.org/mailman/listinfo/python-list

Falsey Enums

2017-07-27 Thread Steve D'Aprano
I has some Enums: from enum import Enum class X(Enum): Falsey = 0 Truthy = 1 Fakey = 2 and I want bool(X.Falsey) to be False, and the others to be True. What should I do? -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse.