Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Also fixes issue #13581: `help(type)` wouldn't display anything.
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index d0c6f62..f45d461 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -754,8 +754,15 @@
hr.maybe()
push(msg)
for name, kind, homecls, value in ok:
- push(self.document(getattr(object, name), name, mod,
- funcs, classes, mdict, object))
+ try:
+ value = getattr(object, name)
+ except Exception:
+ # Some descriptors may meet a failure in their __get__.
+ # (bug #1785)
+ push(self._docdescriptor(name, value, mod))
+ else:
+ push(self.document(value, name, mod,
+ funcs, classes, mdict, object))
push('\n')
return attrs
@@ -796,7 +803,12 @@
mdict = {}
for key, kind, homecls, value in attrs:
mdict[key] = anchor = '#' + name + '-' + key
- value = getattr(object, key)
+ try:
+ value = getattr(object, name)
+ except Exception:
+ # Some descriptors may meet a failure in their __get__.
+ # (bug #1785)
+ pass
try:
# The value may not be hashable (e.g., a data attr with
# a dict or list value).
@@ -1180,8 +1192,15 @@
hr.maybe()
push(msg)
for name, kind, homecls, value in ok:
- push(self.document(getattr(object, name),
- name, mod, object))
+ try:
+ value = getattr(object, name)
+ except Exception:
+ # Some descriptors may meet a failure in their __get__.
+ # (bug #1785)
+ push(self._docdescriptor(name, value, mod))
+ else:
+ push(self.document(value,
+ name, mod, object))
return attrs
def spilldescriptors(msg, attrs, predicate):