diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-03-19 06:47:44 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-03-19 06:47:44 (GMT) |
commit | ac0cea5fab2350aa5f7001a8c524f93c540f0b44 (patch) | |
tree | b5a2c921c5c1a7a7c507a15c4834f05d690c1187 /Lib/test/test_pydoc.py | |
parent | 3a61943b7bd9031293aa03b6505cb29d5630abfa (diff) | |
download | cpython-ac0cea5fab2350aa5f7001a8c524f93c540f0b44.zip cpython-ac0cea5fab2350aa5f7001a8c524f93c540f0b44.tar.gz cpython-ac0cea5fab2350aa5f7001a8c524f93c540f0b44.tar.bz2 |
Merge: #17476: make allmethods actually return all methods.
This fixes a regression relative to Python2. (In 2, methods on a class were
unbound methods and matched the inspect queries being done, in 3 they are just
functions and so were missed).
This is an undocumented function that pydoc itself does not use, but
I found that numpy at least uses it in its documentation generator.
Original patch by Matt Bachmann.
Diffstat (limited to 'Lib/test/test_pydoc.py')
-rw-r--r-- | Lib/test/test_pydoc.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index aa8baf7..8adcdd8 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -420,6 +420,30 @@ class PydocDocTest(unittest.TestCase): self.assertTrue(pydoc.ispackage(test_dir)) os.remove(init_path) + def test_allmethods(self): + # issue 17476: allmethods was no longer returning unbound methods. + # This test is a bit fragile in the face of changes to object and type, + # but I can't think of a better way to do it without duplicating the + # logic of the function under test. + + class TestClass(object): + def method_returning_true(self): + return True + + # What we expect to get back: everything on object... + expected = dict(vars(object)) + # ...plus our unbound method... + expected['method_returning_true'] = TestClass.method_returning_true + # ...but not the non-methods on object. + del expected['__doc__'] + del expected['__class__'] + # inspect resolves descriptors on type into methods, but vars doesn't, + # so we need to update __subclasshook__. + expected['__subclasshook__'] = TestClass.__subclasshook__ + + methods = pydoc.allmethods(TestClass) + self.assertDictEqual(methods, expected) + class PydocImportTest(unittest.TestCase): |