[Python-checkins] cpython: Close issue23900: add default __doc__ to new enumerations that do not specify

ethan.furman python-checkins at python.org
Sun Apr 12 08:23:21 CEST 2015


https://hg.python.org/cpython/rev/684aadcabcc7
changeset:   95554:684aadcabcc7
user:        Ethan Furman <ethan at stoneleaf.us>
date:        Sat Apr 11 23:23:06 2015 -0700
summary:
  Close issue23900: add default __doc__ to new enumerations that do not specify one.

files:
  Lib/enum.py           |   4 ++++
  Lib/test/test_enum.py |  10 +++++-----
  2 files changed, 9 insertions(+), 5 deletions(-)


diff --git a/Lib/enum.py b/Lib/enum.py
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -106,6 +106,10 @@
             raise ValueError('Invalid enum member name: {0}'.format(
                 ','.join(invalid_names)))
 
+        # create a default docstring if one has not been provided
+        if '__doc__' not in classdict:
+            classdict['__doc__'] = 'An enumeration.'
+
         # create our new Enum type
         enum_class = super().__new__(metacls, cls, bases, classdict)
         enum_class._member_names_ = []               # names in definition order
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -1560,9 +1560,7 @@
 Help on class Color in module %s:
 
 class Color(enum.Enum)
- |  Generic enumeration.
- |\x20\x20
- |  Derive from this class to define new enumerations.
+ |  An enumeration.
  |\x20\x20
  |  Method resolution order:
  |      Color
@@ -1626,6 +1624,8 @@
 
 class TestStdLib(unittest.TestCase):
 
+    maxDiff = None
+
     class Color(Enum):
         red = 1
         green = 2
@@ -1646,7 +1646,7 @@
     def test_inspect_getmembers(self):
         values = dict((
                 ('__class__', EnumMeta),
-                ('__doc__', None),
+                ('__doc__', 'An enumeration.'),
                 ('__members__', self.Color.__members__),
                 ('__module__', __name__),
                 ('blue', self.Color.blue),
@@ -1674,7 +1674,7 @@
                 Attribute(name='__class__', kind='data',
                     defining_class=object, object=EnumMeta),
                 Attribute(name='__doc__', kind='data',
-                    defining_class=self.Color, object=None),
+                    defining_class=self.Color, object='An enumeration.'),
                 Attribute(name='__members__', kind='property',
                     defining_class=EnumMeta, object=EnumMeta.__members__),
                 Attribute(name='__module__', kind='data',

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list