8000 Match on Enum with dataclass decorator · Issue #114803 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
Match on Enum with dataclass decorator #114803
Closed
@bedapisl

Description

@bedapisl

Bug report

Bug description:

Hello,
when Enum with @DataClass decorator is used in a match statement, the results seem to be wrong. Consider this example:

from enum import Enum, auto
from dataclasses import dataclass

@dataclass
class Color(str, Enum):
    Red = auto()
    Green = auto()

mode = Color.Green

match mode:
    case Color.Red:
        print(f"Matched RED, actual {mode}")
    case Color.Green:
        print(f"Matched GREEN, actual {mode}")
    case _:
        assert False

I think it should print:

Matched GREEN, actual Color.Green

but it prints:

Matched RED, actual Color.Green

I would suggest this either prints the expected result, or at least produces some error instead of the current behaviour.

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0