diff options
author | Larry Hastings <larry@hastings.org> | 2014-02-21 07:34:46 (GMT) |
---|---|---|
committer | Larry Hastings <larry@hastings.org> | 2014-02-21 07:34:46 (GMT) |
commit | 24a882bb7bc638644b9e66a082439416bfbcf66c (patch) | |
tree | 2aaabe7bf4cb4d0ab0fa4b0b0be09b436d64b4cf /Lib/pydoc.py | |
parent | 8c185ee12e334007b974b3a421704ffb09ecfca8 (diff) | |
download | cpython-24a882bb7bc638644b9e66a082439416bfbcf66c.zip cpython-24a882bb7bc638644b9e66a082439416bfbcf66c.tar.gz cpython-24a882bb7bc638644b9e66a082439416bfbcf66c.tar.bz2 |
Issue #20710: The pydoc summary line no longer displays the "self" parameter
for bound methods. Previous to this change, it displayed "self" for methods
implemented in Python but not methods implemented in C; it is now both
internally consistent and consistent with inspect.Signature.
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-x | Lib/pydoc.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 3873d55..505b7cb 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -137,6 +137,19 @@ def _is_some_method(obj): inspect.isbuiltin(obj) or inspect.ismethoddescriptor(obj)) +def _is_bound_method(fn): + """ + Returns True if fn is a bound method, regardless of whether + fn was implemented in Python or in C. + """ + if inspect.ismethod(fn): + return True + if inspect.isbuiltin(fn): + self = getattr(fn, '__self__', None) + return not (inspect.ismodule(self) or (self is None)) + return False + + def allmethods(cl): methods = {} for key, value in inspect.getmembers(cl, _is_some_method): @@ -898,7 +911,7 @@ class HTMLDoc(Doc): anchor = (cl and cl.__name__ or '') + '-' + name note = '' skipdocs = 0 - if inspect.ismethod(object): + if _is_bound_method(object): imclass = object.__self__.__class__ if cl: if imclass is not cl: @@ -909,7 +922,6 @@ class HTMLDoc(Doc): object.__self__.__class__, mod) else: note = ' unbound %s method' % self.classlink(imclass,mod) - object = object.__func__ if name == realname: title = '<a name="%s"><strong>%s</strong></a>' % (anchor, realname) @@ -924,7 +936,7 @@ class HTMLDoc(Doc): title = '<a name="%s"><strong>%s</strong></a> = %s' % ( anchor, name, reallink) argspec = None - if inspect.isfunction(object) or inspect.isbuiltin(object): + if inspect.isroutine(object): try: signature = inspect.signature(object) except (ValueError, TypeError): @@ -1304,7 +1316,7 @@ location listed above. name = name or realname note = '' skipdocs = 0 - if inspect.ismethod(object): + if _is_bound_method(object): imclass = object.__self__.__class__ if cl: if imclass is not cl: @@ -1315,7 +1327,6 @@ location listed above. object.__self__.__class__, mod) else: note = ' unbound %s method' % classname(imclass,mod) - object = object.__func__ if name == realname: title = self.bold(realname) |