-
Notifications
You must be signed in to change notification settings - Fork 270
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
Extend enum type hint support to more Enum subclasses #500
Conversation
Add support for all subclasses of Enum and a supported basic type. This can be useful in cases where an enum subclass of `Choices` does not make semantic sense.
Codecov Report
@@ Coverage Diff @@
## master #500 +/- ##
=======================================
Coverage 98.58% 98.58%
=======================================
Files 57 57
Lines 5710 5717 +7
=======================================
+ Hits 5629 5636 +7
Misses 81 81
Continue to review full report at Codecov.
|
Hi @jalaziz and thanks for the PR!
i do not understand this statement. Choices is a Django helper wrapping Enum. It should have the same semantics. as we discussed before, we explicitly decided against Enum as there no way to make mypy and DRF happy. Does We can talk about including |
It actually does. See https://docs.python.org/3/library/enum.html#others. The main benefit is that the enum value and a value of the underlying type can be compared. In our case, it gives us nearly the same functionality as
As far as I can tell, DRF seems perfectly happy with Enums defined as
The reason why I chose the |
@tfranzel just wanted to follow up on this. Mostly curious if you're seeing errors with mypy and DRF serialization when using mixin-typed enums. |
hey @jalaziz. i did not know about the i had to deal with the other issues first, but i have it on my todo list. i will deal with it soon. |
excellent PR @jalaziz! i fixed one problem where usage of regular it is quite interesting that DRF recognizes |
Thanks @tfranzel! |
Add support for all subclasses of Enum and a supported basic type. This
can be useful in cases where an enum subclass of
Choices
does not makesemantic sense.
We ran into this while fixing system checks on our codebase. There were instances
of enums defined as subclasses of
(str, Enum)
that work perfectly fine (we're alsousing
django-enumfields
), but threw warnings. While we could useTextChoices
,it doesn't make semantic sense as they are "core" enums.
I'm not sure if there's a mypy issue with these types of enums, but DRF doesn't seem
to mind.