Should nested classes in an Enum be Enum members?

Ben Finney ben+python at benfinney.id.au
Thu Jun 28 20:58:34 EDT 2018


Ian Kelly <ian.g.kelly at gmail.com> writes:

> 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:
> >
> > 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?

Is a Python property a callable attribute?

    >>> class Lorem:
    ...     @property
    ...     def spam(self):
    ...         print(self)
    ... 
    >>> foo = Lorem()
    >>> foo.spam()
    <__main__.Lorem object at 0x7ff5078bc710>
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'NoneType' object is not callable

It seems that no, a property is not a callable attribute.

So I remain dumbfounded as to why anyone would want a class to *both* be
an enumerated type, *and* have callable attributes in its API.

-- 
 \          “It's dangerous to be right when the government is wrong.” |
  `\                                   —Francois Marie Arouet Voltaire |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list