[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Should nested classes in an Enum be Enum members?


On Thu, Jun 28, 2018 at 4:38 AM Ben Finney <ben+python at benfinney.id.au> wrote:
>
> Ethan Furman <ethan at stoneleaf.us> writes:
>
> > Consider the following Enum definition:
> >
> >   class Color(Enum):
> >       RED = 1
> >       GREEN = 2
> >       BLUE = 3
> >       @property
> >       def lower(self):
> >           return self.name.lower()
> >       def spam(self):
> >           return "I like %s eggs and spam!" % self.lower
> >       class SomeClass:
> >           pass
>
> That dumbfounds my intuitions.
>
> Specifically, I can't make sense of why someone would want to have a
> class that is simultaneously behaving as an enumerated type, *and* has
> an API of custom callable attributes.

You don't see value in enum members having properties?