You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
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.
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?
Activity
pythongh-104271: Fix auto() fallback in case of mixed type Enum
itamaro commentedon May 7, 2023
I confirmed the issue and proposed a fix in gh-104279
I think iterating the list of
last_valuesin gh-91457 in sorted order (instead of reversed sorted order) was an oversightin 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.naringas commentedon May 7, 2023
I think the issue came from how I use
Enumwith 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?
sunmy2019 commentedon May 8, 2023
@ethanfurman
itamaro commentedon May 8, 2023
I think so, although it's up to the codeowner (Ethan) to decide if and how this should be fixed
itamaro commentedon May 20, 2023
@ethanfurman what do you think about this issue and proposed fix?
ethanfurman commentedon May 22, 2023
Apologies for the delay, I'll try to get to this this week. In general I agree with the proposed solution.
Merge branch '3.12' into pythongh-104271
Merge branch '3.12' into pythongh-104271
[3.12] gh-104271: Fix auto() fallback in case of mixed type Enum (GH-…
[3.12] pythongh-104271: Fix auto() fallback in case of mixed type Enum (
[3.11] gh-104271: Fix auto() fallback in case of mixed type Enum (GH-…