]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-34750: [Enum] add `_EnumDict.update()` support (GH-23725)
authorEthan Furman <ethan@stoneleaf.us>
Thu, 10 Dec 2020 21:07:00 +0000 (13:07 -0800)
committerGitHub <noreply@github.com>
Thu, 10 Dec 2020 21:07:00 +0000 (13:07 -0800)
commita65828717982e6a56382d7aff738478f5b5b25d0
treec8148582ad4dc68cd969531dc64a1bee8274756b
parentefb13be72cbf49edf591936fafb120fe1b7d59f7
bpo-34750: [Enum] add `_EnumDict.update()` support (GH-23725)

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()
Lib/enum.py
Lib/test/test_enum.py
Misc/NEWS.d/next/Library/2020-12-09-14-15-48.bpo-34750.x8TASR.rst [new file with mode: 0644]