Steven D'Aprano wrote: > 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?
I don't see a problem. As it looks like you cannot subclass Enum subclasses alternative spellings might be isintance(args, (MarxBros, Unique)) or BOTH = set(MarxBros) | set(Unique) arg in MarxBros arg in BOTH -- https://mail.python.org/mailman/listinfo/python-list