This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ethan.furman
Recipients aekoch, ethan.furman
Date 2021-10-14.21:16:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1634246166.51.0.359307459214.issue45473@roundup.psfhosted.org>
In-reply-to
Content
The problem with adding methods is that those names are then unavailable for member names -- at least not without possible confusion.

Also, unlike the `name` and `value` instance attributes which do not hide class attributes (aka members) of the same name, `from_name` is a class method so we couldn't have both a `from_name()` class method and a `from_name` class member at the same time.

If those are issues you know wouldn't a problem for you, you can create your own base Enum class with those methods defined, and then inherit from them:

    class EasyEnum(Enum):
        @classmethod
        def from_name(cls, name):
            return cls[name]
        # etc

     class MyEnum(EasyEnum):
          RED = 1
          # etc.

On the other hand, if you want to use this with any enum, then you'll need to make your own helper functions:

    def from_name(enum, name):
        return enum[name]

    enum_member = from_name(MyEnum, 'RED')
History
Date User Action Args
2021-10-14 21:16:06ethan.furmansetrecipients: + ethan.furman, aekoch
2021-10-14 21:16:06ethan.furmansetmessageid: <1634246166.51.0.359307459214.issue45473@roundup.psfhosted.org>
2021-10-14 21:16:06ethan.furmanlinkissue45473 messages
2021-10-14 21:16:06ethan.furmancreate