Steve,

It looks like what you're trying to achieve is an Enum with more than a 
singleton `.value` exposed on each sub-item.

I was able to achieve something that *looks* like your example using an Enum 
mixin with a custom class:

> from enum import Enum 
  class Labeler:
    @property
    def label(self):
      return self.name.capitalize()

  class Size(Labeler, Enum):
    SMALL = "S"
    MEDIUM = "M"
    LARGE = "L"

  Size.LARGE.label
        'Large'
  Size.LARGE.value
        'L'

More custom values could be added by expanding `Labeler`.

FWIW, I also got a mixin with namedtuple to work:

> from collections import namedtuple as nt
  Key = nt('Key', ('label', 'value'))
  class Foo(Key, Enum)
    Bar = Key(label='Cat', value=5)
    Baz = Key(label='Dog', value=10)

  Foo.Bar.label
        'Cat'

These both were with Python 3.7.

-Brian
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/PEGIJJXIPSMJF7NF64ZJNUARRUIXVRPT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to