]> granicus.if.org Git - python/commitdiff
Issue #20654: Fixed pydoc for enums with zero value. Patch by Vajrasky Kok.
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 19 Feb 2014 21:05:12 +0000 (23:05 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 19 Feb 2014 21:05:12 +0000 (23:05 +0200)
Lib/pydoc.py
Lib/test/test_pydoc.py
Misc/NEWS

index cf164ccfcafff4379cf65c98ef83b75d40a8fa92..3873d5554acf4753e4405a115415970f402491c7 100755 (executable)
@@ -1244,9 +1244,12 @@ location listed above.
                         doc = getdoc(value)
                     else:
                         doc = None
-                    push(self.docother(
-                        getattr(object, name, None) or homecls.__dict__[name],
-                        name, mod, maxlen=70, doc=doc) + '\n')
+                    try:
+                        obj = getattr(object, name)
+                    except AttributeError:
+                        obj = homecls.__dict__[name]
+                    push(self.docother(obj, name, mod, maxlen=70, doc=doc) +
+                         '\n')
             return attrs
 
         attrs = [(name, kind, cls, value)
index 105116a5c00b48a85e93646be7564f6d495a204b..9909b9ae535387c7d3ed5c8848cce326b839ae56 100644 (file)
@@ -386,6 +386,16 @@ class PydocDocTest(unittest.TestCase):
             print_diffs(expected_text, result)
             self.fail("outputs are not equal, see diff above")
 
+    def test_text_enum_member_with_value_zero(self):
+        # Test issue #20654 to ensure enum member with value 0 can be
+        # displayed. It used to throw KeyError: 'zero'.
+        import enum
+        class BinaryInteger(enum.IntEnum):
+            zero = 0
+            one = 1
+        doc = pydoc.render_doc(BinaryInteger)
+        self.assertIn('<BinaryInteger.zero: 0>', doc)
+
     def test_issue8225(self):
         # Test issue8225 to ensure no doc link appears for xml.etree
         result, doc_loc = get_pydoc_text(xml.etree)
index 3cd8d25bb70c2f0375e32c60e3a4c97a7130b516..8c33888b2c2e42b6a4588b735640efb3f24a77b6 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -28,6 +28,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #20654: Fixed pydoc for enums with zero value.  Patch by Vajrasky Kok.
+
 - Issue #20635: Fixed grid_columnconfigure() and grid_rowconfigure() methods of
   Tkinter widgets to work in wantobjects=True mode.