[Python-checkins] cpython: Issue #20654: Fixed pydoc for enums with zero value. Patch by Vajrasky Kok.
serhiy.storchaka
python-checkins at python.org
Wed Feb 19 22:05:34 CET 2014
http://hg.python.org/cpython/rev/8a3e896f0681
changeset: 89284:8a3e896f0681
user: Serhiy Storchaka <storchaka at gmail.com>
date: Wed Feb 19 23:05:12 2014 +0200
summary:
Issue #20654: Fixed pydoc for enums with zero value. Patch by Vajrasky Kok.
files:
Lib/pydoc.py | 9 ++++++---
Lib/test/test_pydoc.py | 10 ++++++++++
Misc/NEWS | 2 ++
3 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -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 --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py
--- a/Lib/test/test_pydoc.py
+++ b/Lib/test/test_pydoc.py
@@ -386,6 +386,16 @@
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)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -28,6 +28,8 @@
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.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list