diff -r ea4c74cc4da5 Lib/pydoc.py --- a/Lib/pydoc.py Mon Feb 17 10:54:30 2014 +0100 +++ b/Lib/pydoc.py Mon Feb 17 22:40:34 2014 +0800 @@ -1244,9 +1244,12 @@ 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) diff -r ea4c74cc4da5 Lib/test/test_pydoc.py --- a/Lib/test/test_pydoc.py Mon Feb 17 10:54:30 2014 +0100 +++ b/Lib/test/test_pydoc.py Mon Feb 17 22:40:34 2014 +0800 @@ -386,6 +386,24 @@ 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'. + module_name = 'binary_integer' + sourcefn = os.path.join(module_name) + os.extsep + "py" + binary_integer_text = """ + import enum + class BinaryInteger(enum.IntEnum): + zero = 0 + one = 1 + """ + binary_integer_text = textwrap.dedent(binary_integer_text) + with open(sourcefn, 'w') as f: + f.write(binary_integer_text) + self.addCleanup(os.unlink, sourcefn) + result = run_pydoc(module_name, _isolated='False') + self.assertIn(b'', result) + def test_issue8225(self): # Test issue8225 to ensure no doc link appears for xml.etree result, doc_loc = get_pydoc_text(xml.etree)