Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 056eb02

Browse files
Issue #20654: Fixed pydoc for enums with zero value. Patch by Vajrasky Kok.
1 parent 4ac30f1 commit 056eb02

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

Lib/pydoc.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,9 +1244,12 @@ def spilldata(msg, attrs, predicate):
12441244
doc = getdoc(value)
12451245
else:
12461246
doc = None
1247-
push(self.docother(
1248-
getattr(object, name, None) or homecls.__dict__[name],
1249-
name, mod, maxlen=70, doc=doc) + '\n')
1247+
try:
1248+
obj = getattr(object, name)
1249+
except AttributeError:
1250+
obj = homecls.__dict__[name]
1251+
push(self.docother(obj, name, mod, maxlen=70, doc=doc) +
1252+
'\n')
12501253
return attrs
12511254

12521255
attrs = [(name, kind, cls, value)

Lib/test/test_pydoc.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,16 @@ def test_text_doc(self):
386386
print_diffs(expected_text, result)
387387
self.fail("outputs are not equal, see diff above")
388388

389+
def test_text_enum_member_with_value_zero(self):
390+
# Test issue #20654 to ensure enum member with value 0 can be
391+
# displayed. It used to throw KeyError: 'zero'.
392+
import enum
393+
class BinaryInteger(enum.IntEnum):
394+
zero = 0
395+
one = 1
396+
doc = pydoc.render_doc(BinaryInteger)
397+
self.assertIn('<BinaryInteger.zero: 0>', doc)
398+
389399
def test_issue8225(self):
390400
# Test issue8225 to ensure no doc link appears for xml.etree
391401
result, doc_loc = get_pydoc_text(xml.etree)

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Core and Builtins
2828
Library
2929
-------
3030

31+
- Issue #20654: Fixed pydoc for enums with zero value. Patch by Vajrasky Kok.
32+
3133
- Issue #20635: Fixed grid_columnconfigure() and grid_rowconfigure() methods of
3234
Tkinter widgets to work in wantobjects=True mode.
3335

0 commit comments

Comments
 (0)