#33193: Clarify enumeration types are true Python Enums
------------------------------------------------+------------------------
Reporter: johnthagen | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 3.2
Severity: Normal | Keywords: enum
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
https://docs.djangoproject.com/en/3.2/ref/models/fields/#field-choices-
enum-types
I was originally hesitant to use the Django "enumeration fields" when I
first read about them because to me the documentation made it sound like
they were "similar" to Python Enums, but something different. I value
using core data types for interop with other non-Django specific code, so
I continued to use django-enumfields (https://github.com/hzdg/django-
enumfields) for several releases. This allowed me to use true Python Enums
which are familiar to use to developers not as versed in Django.
Recently I dug into the Django source code more deeply after hearing about
them again and discovered that indeed the Choices type is really just an
Enum with a little extra magic and some extra helper methods applied to
them (and as such can be used as a normal Python Enum as well).
{{{
class ChoicesMeta(enum.EnumMeta):
"""A metaclass for creating a enum choices."""
...
class Choices(enum.Enum, metaclass=ChoicesMeta):
"""Class for creating enumerated choices."""
}}}
I would recommend modifying the docs in some way, for example:
> These work similar to enum from Python’s standard library, but with some
modifications:
Could be reworded:
> These are true `Enum`s from Python's standard library, but with some
additional extensions added:
--
Ticket URL: <https://code.djangoproject.com/ticket/33193>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.a11ba8d780fe14844f5d312c649752f0%40djangoproject.com.