Skip to content

FW-735: Pipeline failing - changes to Enum class in Python 3.12.10 #4

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

Merged
merged 2 commits into from
Apr 22, 2025

Conversation

richjam
Copy link
Collaborator

@richjam richjam commented Apr 22, 2025

It looks like 3.12.10 included some updates to the Enum class that is causing a new TypeError when setting up a new BitwiseFlag class.

See changelog: https://docs.python.org/release/3.12.10/whatsnew/changelog.html#python-3-12-10

Specifically: gh-108682: Enum: require names=() or type=... to create an empty enum using the functional syntax.
python/cpython#108682

Looks like stricter validation introduced in the enum module. Specifically, when instantiating an enumeration, Python now raises a TypeError if the class has no members defined. This change was implemented to prevent the creation of empty Flag enumerations without explicitly specifying that intention.

In our implementation, overriding the __new__ class method, was interfering with how members are registered during enum class creation and leading to the above type error.

Looks like fix is to just move validation done in __new__ to a new place (__init_subclass__).

Note
This error was introduced in the Github pipeline, but was not showing up when running locally. Github was using the latest 3.12.10 Python release, whereas locally, was still using 3.12.3 (the latest version available in the apt deadsnakes ppa).

Had to install 3.12.10 locally by building the binaries manually.

Copy link
Contributor

@joncooper65 joncooper65 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - and good to learn about init_subclass(cls, **kwargs) and how it affects validation on instantiation - ie having to explicitly iterate over the enum's members.

@richjam richjam merged commit d259d12 into main Apr 22, 2025
3 checks passed
@richjam richjam deleted the bug/FW-735-pipeline-failing branch April 22, 2025 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants