Skip to content
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

Int enum support #161

Merged
merged 1 commit into from
Nov 1, 2024
Merged

Int enum support #161

merged 1 commit into from
Nov 1, 2024

Conversation

slawwan
Copy link
Contributor

@slawwan slawwan commented Oct 30, 2024

No description provided.

@slawwan slawwan requested a review from a team as a code owner October 30, 2024 16:00
Comment on lines +763 to +766
if issubclass(enum_type, str):
return str
if issubclass(enum_type, int):
return int
Copy link

Choose a reason for hiding this comment

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

It would've been nicer to extract the type instead of doing ad-hoc checks but according to the implementation of StrEnum/IntEnum there's not easy way to do it, right? 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm, enum with strings and integers can be declared without using StrEnum/IntEnum and there is an example in tests.

I used the same approach that was before my changes but extended it to support int in addition to str.

I also checked native enum support which was added in marshmallow 3.18, I had thoughts to use it or reuse implementation for v2 but than decided not to change approach used in marshmallow-recipe

Copy link

Choose a reason for hiding this comment

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

enum with strings and integers can be declared without using StrEnum/IntEnum and there is an example in tests.

Exactly, it's just a mix of Enum and int/str, my idea was to get superclasses of resulting enum, filter out enum-related classes and what's left should be a single alien class which is int or str in this case but could also be anything else

Copy link
Contributor Author

@slawwan slawwan Oct 31, 2024

Choose a reason for hiding this comment

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

what are the benefits of suggested approach?

@Pliner Pliner changed the title added int enum support Int enum support Nov 1, 2024
@Pliner Pliner merged commit 70b7bae into anna-money:main Nov 1, 2024
16 checks passed
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.

3 participants