diff options
author | Barry Warsaw <barry@python.org> | 2006-07-27 23:43:15 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2006-07-27 23:43:15 (GMT) |
commit | 00decd7835f0c2488451cedc345f2fb0650378b5 (patch) | |
tree | 88594aceb9e71f753a83234c242f8cedb40e2219 /Lib/inspect.py | |
parent | fc0e61d9b6f3c77f915fc8b4de287b3f8697e167 (diff) | |
download | cpython-00decd7835f0c2488451cedc345f2fb0650378b5.zip cpython-00decd7835f0c2488451cedc345f2fb0650378b5.tar.gz cpython-00decd7835f0c2488451cedc345f2fb0650378b5.tar.bz2 |
Patch #1520294: Support for getset and member descriptors in types.py,
inspect.py, and pydoc.py. Specifically, this allows for querying the type of
an object against these built-in C types and more importantly, for getting
their docstrings printed in the interactive interpreter's help() function.
This patch includes a new built-in module called _types which provides
definitions of getset and member descriptors for use by the types.py module.
These types are exposed as types.GetSetDescriptorType and
types.MemberDescriptorType. Query functions are provided as
inspect.isgetsetdescriptor() and inspect.ismemberdescriptor(). The
implementations of these are robust enough to work with Python implementations
other than CPython, which may not have these fundamental types.
The patch also includes documentation and test suite updates.
I commit these changes now under these guiding principles:
1. Silence is assent. The release manager has not said "no", and of the few
people that cared enough to respond to the thread, the worst vote was "0".
2. It's easier to ask for forgiveness than permission.
3. It's so dang easy to revert stuff in svn, that you could view this as a
forcing function. :)
Windows build patches will follow.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index dc2fa08..0cbf521 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -89,6 +89,40 @@ def isdatadescriptor(object): is not guaranteed.""" return (hasattr(object, "__set__") and hasattr(object, "__get__")) +if hasattr(types, 'MemberDescriptorType'): + # CPython and equivalent + def ismemberdescriptor(object): + """Return true if the object is a member descriptor. + + Member descriptors are specialized descriptors defined in extension + modules.""" + return isinstance(object, types.MemberDescriptorType) +else: + # Other implementations + def ismemberdescriptor(object): + """Return true if the object is a member descriptor. + + Member descriptors are specialized descriptors defined in extension + modules.""" + return False + +if hasattr(types, 'GetSetDescriptorType'): + # CPython and equivalent + def isgetsetdescriptor(object): + """Return true if the object is a getset descriptor. + + getset descriptors are specialized descriptors defined in extension + modules.""" + return isinstance(object, types.GetSetDescriptorType) +else: + # Other implementations + def isgetsetdescriptor(object): + """Return true if the object is a getset descriptor. + + getset descriptors are specialized descriptors defined in extension + modules.""" + return False + def isfunction(object): """Return true if the object is a user-defined function. |