GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Enum works in python 3.10 breaks in 3.11 · Issue #104271 · python/cpython

Enum works in python 3.10 breaks in 3.11 #104271

New issue
Copy link
New issue
Copy link
Closed
Closed
Enum works in python 3.10 breaks in 3.11#104271
Copy link
Assignees
ethanfurman
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@naringas
naringas
opened on May 7, 2023
Issue body actions

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

  • [3.12] gh-104271: Fix auto() fallback in case of mixed type Enum #104279
  • [3.11] [3.12] gh-104271: Fix auto() fallback in case of mixed type Enum (GH-104279) #104809

Activity

  1. naringas
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on May 7, 2023
  2. itamaro
    added a commit that references this issue on May 7, 2023

    pythongh-104271: Fix auto() fallback in case of mixed type Enum

    09bfba4
  3. itamaro commented on May 7, 2023

    @itamaro
    itamaro
    on May 7, 2023
    Contributor
    More actions

    I confirmed the issue and proposed a fix in gh-104279

    I think iterating the list of last_values in gh-91457 in sorted order (instead of reversed sorted order) was an oversight

    in any case, @naringas, it seems that this use of auto() will be deprecated in 3.13.
    you should be able to fix this in your code by overriding _generate_next_value_ to get your desired behavior in a way that works with older python versions.

    Reacted by b s
  4. naringas commented on May 7, 2023

    @naringas
    naringas
    on May 7, 2023
    Author
    More actions

    in any case, @naringas, it seems that this use of auto() will be deprecated in 3.13. you should be able to fix this in your code by overriding _generate_next_value_ to get your desired behavior in a way that works with older python versions.

    I think the issue came from how I use Enum with mixed values; I have values either as strings, or 'auto'.

    Now that I've had to think about this, I realize expect unique (hence the decorator to error out if this fails) numerical values. I think this is a valid expectation for a unique Enum type with mixed values.

    question: this issue gets closed if/when the PR gets merged?

  5. sunmy2019 commented on May 8, 2023

    @sunmy2019
    sunmy2019
    on May 8, 2023
    Member
    More actions

    @ethanfurman

  6. itamaro commented on May 8, 2023

    @itamaro
    itamaro
    on May 8, 2023
    Contributor
    More actions

    question: this issue gets closed if/when the PR gets merged?

    I think so, although it's up to the codeowner (Ethan) to decide if and how this should be fixed

  7. AlexWaygood
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    3.11only security fixesonly security fixes
    3.12only security fixesonly security fixes
    on May 8, 2023
  8. itamaro commented on May 20, 2023

    @itamaro
    itamaro
    on May 20, 2023
    Contributor
    More actions

    @ethanfurman what do you think about this issue and proposed fix?

  9. ethanfurman commented on May 22, 2023

    @ethanfurman
    ethanfurman
    on May 22, 2023
    Member
    More actions

    Apologies for the delay, I'll try to get to this this week. In general I agree with the proposed solution.

    Reacted by Itamar Oren
  10. ethanfurman
    self-assigned this
    on May 23, 2023
  11. ethanfurman
    added 3 commits that reference this issue on May 23, 2023

    Merge branch '3.12' into pythongh-104271

    0f0de17

    Merge branch '3.12' into pythongh-104271

    fa2ea05

    [3.12] gh-104271: Fix auto() fallback in case of mixed type Enum (GH-…

    f4e2049
  12. miss-islington
    added a commit that references this issue on May 23, 2023

    [3.12] pythongh-104271: Fix auto() fallback in case of mixed type Enum (

    10939d3
  13. ethanfurman
    added a commit that references this issue on May 23, 2023

    [3.11] gh-104271: Fix auto() fallback in case of mixed type Enum (GH-…

    582aadc
  14. ethanfurman
    closed this as completedon May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @ethanfurman
    ethanfurman

Labels

3.11only security fixesonly security fixes3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.