summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/inspect.py10
-rwxr-xr-xLib/pydoc.py4
-rw-r--r--Lib/test/test_inspect.py3
3 files changed, 15 insertions, 2 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 4baebe0..a2ea739 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -78,6 +78,16 @@ def ismethoddescriptor(object):
and not isfunction(object)
and not isclass(object))
+def isdatadescriptor(object):
+ """Return true if the object is a data descriptor.
+
+ Data descriptors have both a __get__ and a __set__ attribute. Examples are
+ properties (defined in Python) and getsets and members (defined in C).
+ Typically, data descriptors will also have __name__ and __doc__ attributes
+ (properties, getsets, and members have both of these attributes), but this
+ is not guaranteed."""
+ return (hasattr(object, "__set__") and hasattr(object, "__get__"))
+
def isfunction(object):
"""Return true if the object is a user-defined function.
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 7f0addd..8e5064a 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -686,7 +686,7 @@ class HTMLDoc(Doc):
push(msg)
for name, kind, homecls, value in ok:
base = self.docother(getattr(object, name), name, mod)
- if callable(value):
+ if callable(value) or inspect.isdatadescriptor(value):
doc = getattr(value, "__doc__", None)
else:
doc = None
@@ -1087,7 +1087,7 @@ class TextDoc(Doc):
hr.maybe()
push(msg)
for name, kind, homecls, value in ok:
- if callable(value):
+ if callable(value) or inspect.isdatadescriptor(value):
doc = getattr(value, "__doc__", None)
else:
doc = None
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index d253f26..33e0b0d 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -61,6 +61,7 @@ class FesteringGob(MalodorousPervert, ParrotDroppings):
# isbuiltin, isroutine, getmembers, getdoc, getfile, getmodule,
# getsourcefile, getcomments, getsource, getclasstree, getargspec,
# getargvalues, formatargspec, formatargvalues, currentframe, stack, trace
+# isdatadescriptor
from test.test_support import TestFailed, TESTFN
import sys, imp, os, string
@@ -104,6 +105,8 @@ istest(inspect.ismethod, 'mod.StupidGit.abuse')
istest(inspect.ismethod, 'git.argue')
istest(inspect.ismodule, 'mod')
istest(inspect.istraceback, 'tb')
+istest(inspect.isdatadescriptor, '__builtins__.file.closed')
+istest(inspect.isdatadescriptor, '__builtins__.file.softspace')
test(inspect.isroutine(mod.spam), 'isroutine(mod.spam)')
test(inspect.isroutine([].count), 'isroutine([].count)')