]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.12] gh-114071: [Enum] update docs and code for tuples/subclasses (GH-114871) ...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 8 Feb 2024 22:01:38 +0000 (23:01 +0100)
committerGitHub <noreply@github.com>
Thu, 8 Feb 2024 22:01:38 +0000 (14:01 -0800)
commit7d2f88edf0365c2d9b872dc7847b9a77a5df8aac
tree07cb06d725b22dce5f29005e463414b99673dad7
parentdc01c84ed066ec19704f018d3925dc2fe812a2a8
[3.12] gh-114071: [Enum] update docs and code for tuples/subclasses (GH-114871) (GH-114993)

Update documentation with `__new__` and `__init__` entries.

Support use of `auto()` in tuple subclasses on member assignment lines.  Previously, auto() was only supported on the member definition line either solo or as part of a tuple:

    RED = auto()
    BLUE = auto(), 'azul'

However, since Python itself supports using tuple subclasses where tuples are expected, e.g.:

    from collections import namedtuple
    T = namedtuple('T', 'first second third')

    def test(one, two, three):
        print(one, two, three)

    test(*T(4, 5, 6))
    GH- 4 5 6

it made sense to also support tuple subclasses in enum definitions.
(cherry picked from commit ff7588b729a2a414ea189a2012904da3fbd1401c)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Doc/library/enum.rst
Lib/enum.py
Lib/test/test_enum.py
Misc/NEWS.d/next/Library/2024-02-01-10-19-11.gh-issue-114071.vkm2G_.rst [new file with mode: 0644]