*** Doc\lib\libinspect.tex.orig Tue Apr 23 14:21:20 2002 --- Doc\lib\libinspect.tex Mon Apr 21 09:23:06 2003 *************** *** 161,166 **** --- 161,191 ---- Return true if the object is a user-defined or built-in function or method. \end{funcdesc} + \begin{funcdesc}{ismethoddescriptor}{object} + Return true if the object is a method descriptor, but not if ismethod() or + isclass() or isfunction() are true. + + This is new as of Python 2.2, and, for example, is true of int.__add__. + An object passing this test has a __get__ attribute but not a __set__ + attribute, but beyond that the set of attributes varies. __name__ is + usually sensible, and __doc__ often is. + + Methods implemented via descriptors that also pass one of the other + tests return false from the ismethoddescriptor() test, simply because + the other tests promise more -- you can, e.g., count on having the + im_func attribute (etc) when an object passes ismethod(). + \end{funcdesc} + + \begin{funcdesc}{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. + \end{funcdesc} + \subsection{Retrieving source code \label{inspect-source}} *** Lib\inspect.py.orig Fri Mar 28 08:29:50 2003 --- Lib\inspect.py Mon Apr 21 09:23:15 2003 *************** *** 78,83 **** --- 78,93 ---- 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. *** Lib\pydoc.py.orig Sun Mar 30 12:31:34 2003 --- Lib\pydoc.py Mon Apr 21 08:50:31 2003 *************** *** 686,692 **** push(msg) for name, kind, homecls, value in ok: base = self.docother(getattr(object, name), name, mod) ! if callable(value): doc = getattr(value, "__doc__", None) else: doc = None --- 686,692 ---- push(msg) for name, kind, homecls, value in ok: base = self.docother(getattr(object, name), name, mod) ! if callable(value) or inspect.isdatadescriptor(value): doc = getattr(value, "__doc__", None) else: doc = None *************** *** 1087,1093 **** hr.maybe() push(msg) for name, kind, homecls, value in ok: ! if callable(value): doc = getattr(value, "__doc__", None) else: doc = None --- 1087,1093 ---- hr.maybe() push(msg) for name, kind, homecls, value in ok: ! if callable(value) or inspect.isdatadescriptor(value): doc = getattr(value, "__doc__", None) else: doc = None *** Lib\test\test_inspect.py.orig Fri Nov 29 19:53:15 2002 --- Lib\test\test_inspect.py Mon Apr 21 09:23:47 2003 *************** *** 61,66 **** --- 61,67 ---- # 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,109 **** --- 105,112 ---- 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)')