Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a624eb0

Browse files
committed
document and therefore fix #136
1 parent f9103c1 commit a624eb0

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

‎doc/source/changelog.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Change Log
77
v2.2.4 (2025年09月21日)
88
===================
99

10+
* Documented `Choices derived enum-properties types do not unpack member tuples on declaration <https://github.com/django-commons/django-enum/issues/136>`_
1011
* Implemented `Support Python 3.14 <https://github.com/django-commons/django-enum/issues/135>`_
1112
* Fixed `Avoid depending on typing_extensions. <https://github.com/django-commons/django-enum/pull/134>`_
1213

‎src/django_enum/choices.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,34 @@ class FlagChoices( # type: ignore
130130
"""
131131
An integer flag enumeration type that accepts enum-properties property
132132
lists.
133+
134+
Note that on Pythons before 3.14 there is a quirk to the choices type where
135+
member tuples including the label are not unpacked on declaration. This means if you
136+
want to define composite fields on these versions it might look like this on
137+
Python < 3.14:
138+
139+
.. code-block:: python
140+
141+
class MyFlag(FlagChoices):
142+
A = 1 << 0, "a"
143+
B = 1 << 1, "b"
144+
C = 1 << 2, "c"
145+
AB = A[0] | B[0], "ab" # Python < 3.14
146+
BC = B[0] | C[0], "bc" # Python < 3.14
147+
ABC = A[0] | B[0] | C[0], "abc" # Python < 3.14
148+
149+
And this on Python >= 3.14:
150+
151+
.. code-block:: python
152+
153+
class MyFlag(FlagChoices):
154+
A = 1 << 0, "a"
155+
B = 1 << 1, "b"
156+
C = 1 << 2, "c"
157+
AB = A | B, "ab" # Python >= 3.14
158+
BC = B | C, "bc" # Python >= 3.14
159+
ABC = A | B | C, "abc" # Python >= 3.14
160+
133161
"""
134162

135163
def __hash__(self):

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /