diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 3a461714821d38..54e6ce8b25bcfc 100644 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -958,8 +958,7 @@ def docroutine(self, object, name=None, mod=None, if name == realname: title = '%s' % (anchor, realname) else: - if (cl and realname in cl.__dict__ and - cl.__dict__[realname] is object): + if cl and inspect.getattr_static(cl, realname, []) is object: reallink = '%s' % ( cl.__name__ + '-' + realname, realname) skipdocs = 1 @@ -1393,8 +1392,7 @@ def docroutine(self, object, name=None, mod=None, cl=None): if name == realname: title = self.bold(realname) else: - if (cl and realname in cl.__dict__ and - cl.__dict__[realname] is object): + if cl and inspect.getattr_static(cl, realname, []) is object: skipdocs = 1 title = self.bold(name) + ' = ' + realname argspec = None diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index 6cd81ec5c334a7..d521deda176002 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -417,6 +417,7 @@ def call_url_handler(self, url, expected_title): class PydocDocTest(unittest.TestCase): + maxDiff = None @unittest.skipIf(sys.flags.optimize >= 2, "Docstrings are omitted with -O2 and above") @@ -766,6 +767,104 @@ def method_returning_true(self): methods = pydoc.allmethods(TestClass) self.assertDictEqual(methods, expected) + def test_method_aliases(self): + class A: + def tkraise(self, aboveThis=None): + """Raise this widget in the stacking order.""" + lift = tkraise + def a_size(self): + """Return size""" + class B(A): + def itemconfigure(self, tagOrId, cnf=None, **kw): + """Configure resources of an item TAGORID.""" + itemconfig = itemconfigure + b_size = A.a_size + + doc = pydoc.render_doc(B) + # clean up the extra text formatting that pydoc performs + doc = re.sub('\b.', '', doc) + self.assertEqual(doc, '''\ +Python Library Documentation: class B in module %s + +class B(A) + | Method resolution order: + | B + | A + | builtins.object + |\x20\x20 + | Methods defined here: + |\x20\x20 + | b_size = a_size(self) + |\x20\x20 + | itemconfig = itemconfigure(self, tagOrId, cnf=None, **kw) + |\x20\x20 + | itemconfigure(self, tagOrId, cnf=None, **kw) + | Configure resources of an item TAGORID. + |\x20\x20 + | ---------------------------------------------------------------------- + | Methods inherited from A: + |\x20\x20 + | a_size(self) + | Return size + |\x20\x20 + | lift = tkraise(self, aboveThis=None) + |\x20\x20 + | tkraise(self, aboveThis=None) + | Raise this widget in the stacking order. + |\x20\x20 + | ---------------------------------------------------------------------- + | Data descriptors inherited from A: + |\x20\x20 + | __dict__ + | dictionary for instance variables (if defined) + |\x20\x20 + | __weakref__ + | list of weak references to the object (if defined) +''' % __name__) + + doc = pydoc.render_doc(B, renderer=pydoc.HTMLDoc()) + self.assertEqual(doc, '''\ +Python Library Documentation: class B in module %s + +
+
| +class B(A) | ||
| + |
+Methods defined here: + + +
+Methods inherited from A: +
+Data descriptors inherited from A: +
| |