Skip to content

Enum works in python 3.10 breaks in 3.11 #104271

Closed
@naringas

Description

@naringas

Bug report

I have this (simplified) code

from enum import Enum, auto, unique

@unique
class TokenType(Enum):
	# // Single-character tokens.
	LEFT_PAREN = '('
	
	# // Literals.
	IDENTIFIER = auto()
	STRING = auto()
	NUMBER = auto()
	
	# // Keywords.
	AND = 'and'
	
	WHILE = 'while'

	EOF = auto()

I tested this (I developed it) using python 3.10.8.

My friend ran it in 3.11.3 and it breaks like this:

  File ".../3.11.3/lib/python3.11/enum.py", line 1561, in unique
    raise ValueError('duplicate values found in %r: %s' %
ValueError: duplicate values found in <enum 'TokenType'>: NUMBER -> STRING, EOF -> STRING

We can work around the problem using a StrEnum and it's all fine. But I think this is a regression bug. I don't think my code should break like this because the standard library changed.
Also, fyi, StrEnum is new in 3.11 so I cannot just adjust my own code (which works well).

Linked PRs

Metadata

Metadata

Assignees

Labels

3.11only security fixes3.12only security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions