-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instantiation of an empty Enum with any value no longer throws ValueError
#109022
Comments
In Python 3.10- the code would check the number of arguments to determine if a member lookup or a functional enum creation was intended. In Python 3.11+ it decides which path to take based on the presence of members:
We then ended up with the The last bug-fix resolves that issue, but now we have the current issue of creating a new enum class with what looks like a member lookup. That didn't work before 3.12, so we could certainly go back to making that an error (and perhaps getting better error messages). |
…9048) add guard so that ``Enum('bar')`` raises a TypeError instead of creating a new enum class called `bar`. To create the new but empty class, use: huh = Enum('bar', names=())
…ythonGH-109048) add guard so that ``Enum('bar')`` raises a TypeError instead of creating a new enum class called `bar`. To create the new but empty class, use: huh = Enum('bar', names=()) (cherry picked from commit c74e440) Co-authored-by: Ethan Furman <[email protected]>
…GH-109048) (#109122) gh-109022: [Enum] require `names=()` to create empty enum type (GH-109048) add guard so that ``Enum('bar')`` raises a TypeError instead of creating a new enum class called `bar`. To create the new but empty class, use: huh = Enum('bar', names=()) (cherry picked from commit c74e440) Co-authored-by: Ethan Furman <[email protected]>
Thanks! |
Bug report
Bug description:
On Python < 3.12 instantiation of an empty
Enum
with any value resulted inValueError
, but on 3.12.0rc2 it returns<enum 'bar'>
without errors. On 3.12.0rc1 it resulted inTypeError: 'NoneType' object is not iterable
that was addressed in this issue:NoneType
object is not iterable #106928I'm not sure if it's intended or not but just in case, I'll write about it, so that if it's unintended behaviour it could be fixed before the final release. For me
ValueError
was more consistent but I don't see a practical reason to use empty enums anyway and I'm fine if this issue is going to be closed.CPython versions tested on:
3.12
Operating systems tested on:
macOS
Linked PRs
names=()
to create empty enum type #109048names=()
to create empty enum type (GH-109048) #109122The text was updated successfully, but these errors were encountered: