FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-34750: [Enum] add `_EnumDict.update()` support by ethanfurman · Pull Request #23725 · python/cpython · GitHub

Repository navigation

bpo-34750: [Enum] add _EnumDict.update() support - #23725

Merged
ethanfurman merged 1 commit into
python:masterfrom
ethanfurman:enum-dynamic_members_static_methods
Dec 10, 2020
Merged

ethanfurman merged 1 commit into
python:masterfrom
ethanfurman:enum-dynamic_members_static_methods

Conversation

ethanfurman commented Dec 9, 2020 •
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Member

This allows easier Enum construction in unusual cases, such as including dynamic member definitions into a class definition:

# created dynamically
foo_defines = {'FOO_CAT': 'aloof', 'BAR_DOG': 'friendly', 'FOO_HORSE': 'big'}

class Foo(Enum):
    vars().update({
            k: v
            for k, v in foo_defines.items()
            if k.startswith('FOO_')
            })
    def upper(self):
        # example method
        return self.value.upper()

https://bugs.python.org/issue34750

ethanfurman merged commit a658287 into python:master Dec 10, 2020
ethanfurman deleted the enum-dynamic_members_static_methods branch December 10, 2020 21:07
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
This allows easier Enum construction in unusual cases, such as including dynamic member definitions into a class definition:

# created dynamically
foo_defines = {'FOO_CAT': 'aloof', 'BAR_DOG': 'friendly', 'FOO_HORSE': 'big'}

class Foo(Enum):
    vars().update({
            k: v
            for k, v in foo_defines.items()
            if k.startswith('FOO_')
            })
    def upper(self):
        # example method
        return self.value.upper()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL