mirror of
https://github.com/python/cpython.git
synced 2025-07-28 13:44:43 +00:00
Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Also fixes issue #13581: `help(type)` wouldn't display anything.
This commit is contained in:
parent
587c7381c7
commit
b8572a1673
4 changed files with 158 additions and 32 deletions
29
Lib/pydoc.py
29
Lib/pydoc.py
|
@ -740,8 +740,15 @@ class HTMLDoc(Doc):
|
|||
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
|
||||
|
||||
|
@ -781,7 +788,12 @@ class HTMLDoc(Doc):
|
|||
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).
|
||||
|
@ -1161,8 +1173,15 @@ class TextDoc(Doc):
|
|||
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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue