Re: Enums: making a single enum

2018-11-17 Thread Marko Rauhamaa
Ian Kelly : > On Fri, May 25, 2018 at 11:00 PM, Chris Angelico wrote: >> On Sat, May 26, 2018 at 2:46 PM, Steven D'Aprano >>> class State(Enum): >>> Maybe = 2 >> >> # Tri-state logic >> Maybe = object() > > The enum has a nice __str__ though. That's why I usually use string sentinels:

Re: Enums: making a single enum

2018-05-26 Thread Ethan Furman
On 05/26/2018 01:00 AM, Steven D'Aprano wrote: I wish there was a simpler way to define symbols with identity but no state or behaviour... Check out the Constant class in aenum. You still might want to customize the repr, though. -- ~Ethan~ --

Re: Enums: making a single enum

2018-05-26 Thread Steven D'Aprano
On Sat, 26 May 2018 23:54:51 +1000, Chris Angelico wrote: > Seems pretty non-controversial, which means it's almost guaranteed to > reach 100+ posts debating what the name should be. Including: * 27 posts declaring that using such singleton symbols is completely un-Pythonic and is sure to

Re: Enums: making a single enum

2018-05-26 Thread Chris Angelico
On Sat, May 26, 2018 at 6:50 PM, Steven D'Aprano wrote: > On Sat, 26 May 2018 18:14:08 +1000, Chris Angelico wrote: > >> On Sat, May 26, 2018 at 6:00 PM, Steven D'Aprano >> wrote: >>> Actually I don't really need all the

Re: Enums: making a single enum

2018-05-26 Thread Peter Otten
Steven D'Aprano wrote: > Am I silly for wanting to make a single enum? > > I have a three-state flag, True, False or Maybe. Is is confusing or bad > practice to make a single enum for the Maybe case? > > > from enum import Enum > class State(Enum): > Maybe = 2 > > Maybe = State.Maybe >

Re: Enums: making a single enum

2018-05-26 Thread Marko Rauhamaa
Ian Kelly : > On Fri, May 25, 2018 at 11:00 PM, Chris Angelico wrote: >> # Tri-state logic >> Maybe = object() > > The enum has a nice __str__ though. I use strings for enums: class X: HERE = "HERE" THERE = "THERE" EVERYWHERE =

Re: Enums: making a single enum

2018-05-26 Thread Serhiy Storchaka
26.05.18 08:07, Ian Kelly пише: On Fri, May 25, 2018 at 11:00 PM, Chris Angelico wrote: On Sat, May 26, 2018 at 2:46 PM, Steven D'Aprano wrote: Am I silly for wanting to make a single enum? I have a three-state flag, True, False or

Re: Enums: making a single enum

2018-05-26 Thread Steven D'Aprano
On Sat, 26 May 2018 18:14:08 +1000, Chris Angelico wrote: > On Sat, May 26, 2018 at 6:00 PM, Steven D'Aprano > wrote: >> Actually I don't really need all the features of Enums, I might just >> define my own class: >> >> >> class Maybe: >> def

Re: Enums: making a single enum

2018-05-26 Thread Chris Angelico
On Sat, May 26, 2018 at 6:00 PM, Steven D'Aprano wrote: > Actually I don't really need all the features of Enums, I might just > define my own class: > > > class Maybe: > def __repr__(self): > return "Maybe" > > Maybe = Maybe() > > > > I wish

Re: Enums: making a single enum

2018-05-26 Thread Steven D'Aprano
On Fri, 25 May 2018 23:07:47 -0600, Ian Kelly wrote: > On Fri, May 25, 2018 at 11:00 PM, Chris Angelico > wrote: >> On Sat, May 26, 2018 at 2:46 PM, Steven D'Aprano >> wrote: [...] >>> Is there a better way of handling a three-state flag

Re: Enums: making a single enum

2018-05-25 Thread Chris Angelico
On Sat, May 26, 2018 at 3:07 PM, Ian Kelly wrote: > On Fri, May 25, 2018 at 11:00 PM, Chris Angelico wrote: >> On Sat, May 26, 2018 at 2:46 PM, Steven D'Aprano >> wrote: >>> Am I silly for wanting to make a single

Re: Enums: making a single enum

2018-05-25 Thread Ian Kelly
On Fri, May 25, 2018 at 11:00 PM, Chris Angelico wrote: > On Sat, May 26, 2018 at 2:46 PM, Steven D'Aprano > wrote: >> Am I silly for wanting to make a single enum? >> >> I have a three-state flag, True, False or Maybe. Is is confusing or

Re: Enums: making a single enum

2018-05-25 Thread Chris Angelico
On Sat, May 26, 2018 at 2:46 PM, Steven D'Aprano wrote: > Am I silly for wanting to make a single enum? > > I have a three-state flag, True, False or Maybe. Is is confusing or bad > practice to make a single enum for the Maybe case? > > > from enum import

Enums: making a single enum

2018-05-25 Thread Steven D'Aprano
Am I silly for wanting to make a single enum? I have a three-state flag, True, False or Maybe. Is is confusing or bad practice to make a single enum for the Maybe case? from enum import Enum class State(Enum): Maybe = 2 Maybe = State.Maybe del State Is there a better way of handling a