summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2016-08-20 14:19:31 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2016-08-20 14:19:31 (GMT)
commite8e61277ff31d7b5ae87ca21808c4a6fbdab4954 (patch)
treef44a362609960627ade0521c9b8de0c1dfbc2693 /Doc
parent3e458755782e8f63dd9eb29cb134c2b65657d17f (diff)
downloadcpython-e8e61277ff31d7b5ae87ca21808c4a6fbdab4954.zip
cpython-e8e61277ff31d7b5ae87ca21808c4a6fbdab4954.tar.gz
cpython-e8e61277ff31d7b5ae87ca21808c4a6fbdab4954.tar.bz2
issue26981: add _order_ compatibility shim to enum.Enum
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/enum.rst21
1 files changed, 20 insertions, 1 deletions
diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst
index 2111d1c..827bab0 100644
--- a/Doc/library/enum.rst
+++ b/Doc/library/enum.rst
@@ -257,7 +257,7 @@ members are not integers (but see `IntEnum`_ below)::
>>> Color.red < Color.blue
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
- TypeError: unorderable types: Color() < Color()
+ TypeError: '<' not supported between instances of 'Color' and 'Color'
Equality comparisons are defined though::
@@ -776,3 +776,22 @@ appropriately.
If you wish to change how :class:`Enum` members are looked up you should either
write a helper function or a :func:`classmethod` for the :class:`Enum`
subclass.
+
+To help keep Python 2 / Python 3 code in sync a user-specified :attr:`_order_`,
+if provided, will be checked to ensure the actual order of the enumeration
+matches::
+
+ >>> class Color(Enum):
+ ... _order_ = 'red green blue'
+ ... red = 1
+ ... blue = 3
+ ... green = 2
+ ...
+ Traceback (most recent call last):
+ ...
+ TypeError: member order does not match _order_
+
+.. note::
+
+ In Python 2 code the :attr:`_order_` attribute is necessary as definition
+ order is lost during class creation.