summaryrefslogtreecommitdiffstats
path: root/Lib/enum.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2013-09-15 23:59:35 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2013-09-15 23:59:35 (GMT)
commitc850f34220888838110cb07909fd80f3648ad2ba (patch)
treec193b3046dc2d68e32648f989c40049005aff415 /Lib/enum.py
parent173a157e725579eec1f28f8c9d53d6761ba6c79f (diff)
downloadcpython-c850f34220888838110cb07909fd80f3648ad2ba.zip
cpython-c850f34220888838110cb07909fd80f3648ad2ba.tar.gz
cpython-c850f34220888838110cb07909fd80f3648ad2ba.tar.bz2
Close #18693: Enum is now more help() friendly.
Diffstat (limited to 'Lib/enum.py')
-rw-r--r--Lib/enum.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index 40546da..86f94d9 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -16,6 +16,8 @@ class _RouteClassAttributeToGetattr:
"""
def __init__(self, fget=None):
self.fget = fget
+ if fget.__doc__ is not None:
+ self.__doc__ = fget.__doc__
def __get__(self, instance, ownerclass=None):
if instance is None:
@@ -166,6 +168,7 @@ class EnumMeta(type):
enum_member._value_ = member_type(*args)
value = enum_member._value_
enum_member._name_ = member_name
+ enum_member.__objclass__ = enum_class
enum_member.__init__(*args)
# If another member with the same value was already defined, the
# new member becomes an alias to the existing one.
@@ -229,7 +232,7 @@ class EnumMeta(type):
return isinstance(member, cls) and member.name in cls._member_map_
def __dir__(self):
- return ['__class__', '__doc__', '__members__'] + self._member_names_
+ return ['__class__', '__doc__', '__members__', '__module__'] + self._member_names_
def __getattr__(cls, name):
"""Return the enum member matching `name`
@@ -455,7 +458,8 @@ class Enum(metaclass=EnumMeta):
return "%s.%s" % (self.__class__.__name__, self._name_)
def __dir__(self):
- return (['__class__', '__doc__', 'name', 'value'])
+ added_behavior = [m for m in self.__class__.__dict__ if m[0] != '_']
+ return ['__class__', '__doc__', '__module__', 'name', 'value'] + added_behavior
def __eq__(self, other):
if type(other) is self.__class__:
@@ -492,10 +496,12 @@ class Enum(metaclass=EnumMeta):
@_RouteClassAttributeToGetattr
def name(self):
+ """The name of the Enum member."""
return self._name_
@_RouteClassAttributeToGetattr
def value(self):
+ """The value of the Enum member."""
return self._value_