Enum with only a single member
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon Jan 9 23:43:27 EST 2017
Is it silly to create an enumeration with only a single member? That is, a
singleton enum?
from enum import Enum
class Unique(Enum):
FOO = auto()
The reason I ask is that I have two functions that take an enum argument. The
first takes one of three enums:
class MarxBros(Enum):
GROUCHO = 1
CHICO = 2
HARPO = 3
and the second takes *either* one of those three, or a fourth distinct value.
So in my two functions, I have something like this:
def spam(arg):
if isinstance(arg, MarxBros):
...
def ham(arg):
if isinstance(arg, MarxBros) or arg is Unique.FOO:
...
Good, bad or indifferent?
--
Steven
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." - Jon Ronson
More information about the Python-list
mailing list