summaryrefslogtreecommitdiffstats
path: root/Lib/enum.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2013-09-15 01:11:24 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2013-09-15 01:11:24 (GMT)
commit2131a4a2fc933132c8f2b1f97b3bbf246cccc669 (patch)
treed3c00a2914f976802467faabe45918fdb92f2714 /Lib/enum.py
parent5589bd109adf9cdf1eec9ad78d4250b9f9b078ea (diff)
downloadcpython-2131a4a2fc933132c8f2b1f97b3bbf246cccc669.zip
cpython-2131a4a2fc933132c8f2b1f97b3bbf246cccc669.tar.gz
cpython-2131a4a2fc933132c8f2b1f97b3bbf246cccc669.tar.bz2
Add __reversed__ to Enum. Minor code reorg (moved __members__ to be in alpha order).
Diffstat (limited to 'Lib/enum.py')
-rw-r--r--Lib/enum.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index 82058ae..0d72f3e 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -225,16 +225,6 @@ class EnumMeta(type):
def __dir__(self):
return ['__class__', '__doc__', '__members__'] + self._member_names_
- @property
- def __members__(cls):
- """Returns a mapping of member name->value.
-
- This mapping lists all enum members, including aliases. Note that this
- is a read-only view of the internal mapping.
-
- """
- return MappingProxyType(cls._member_map_)
-
def __getattr__(cls, name):
"""Return the enum member matching `name`
@@ -260,9 +250,22 @@ class EnumMeta(type):
def __len__(cls):
return len(cls._member_names_)
+ @property
+ def __members__(cls):
+ """Returns a mapping of member name->value.
+
+ This mapping lists all enum members, including aliases. Note that this
+ is a read-only view of the internal mapping.
+
+ """
+ return MappingProxyType(cls._member_map_)
+
def __repr__(cls):
return "<enum %r>" % cls.__name__
+ def __reversed__(cls):
+ return (cls._member_map_[name] for name in reversed(cls._member_names_))
+
def __setattr__(cls, name, value):
"""Block attempts to reassign Enum members.