diff options
author | Éric Araujo <merwok@netwok.org> | 2011-07-29 15:34:35 (GMT) |
---|---|---|
committer | Éric Araujo <merwok@netwok.org> | 2011-07-29 15:34:35 (GMT) |
commit | 9a528306b9ba967cfd04b23ac7b18fdb1091327d (patch) | |
tree | 9cfc11e0e3da2db1fd1bd53ae2d01369d0225666 | |
parent | 271208e22536a0d2e736aa85eb8d6b97e903266c (diff) | |
download | cpython-9a528306b9ba967cfd04b23ac7b18fdb1091327d.zip cpython-9a528306b9ba967cfd04b23ac7b18fdb1091327d.tar.gz cpython-9a528306b9ba967cfd04b23ac7b18fdb1091327d.tar.bz2 |
Make “pydoc somebuiltin.somemethod” work (#8887)
-rwxr-xr-x | Lib/pydoc.py | 13 | ||||
-rw-r--r-- | Lib/test/test_pydoc.py | 21 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 29 insertions, 8 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py index ecbdb44..d08d1ac 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1454,13 +1454,14 @@ def locate(path, forceload=0): else: break if module: object = module - for part in parts[n:]: - try: object = getattr(object, part) - except AttributeError: return None - return object else: - if hasattr(__builtin__, path): - return getattr(__builtin__, path) + object = __builtin__ + for part in parts[n:]: + try: + object = getattr(object, part) + except AttributeError: + return None + return object # --------------------------------------- interactive interpreter interface diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index 8591693..d98faec 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -1,8 +1,8 @@ -import sys import os -import os.path +import sys import difflib import subprocess +import __builtin__ import re import pydoc import inspect @@ -357,6 +357,23 @@ class TestHelper(unittest.TestCase): self.assertEqual(sorted(pydoc.Helper.keywords), sorted(keyword.kwlist)) + def test_builtin(self): + for name in ('str', 'str.translate', '__builtin__.str', + '__builtin__.str.translate'): + # test low-level function + self.assertIsNotNone(pydoc.locate(name)) + # test high-level function + try: + pydoc.render_doc(name) + except ImportError: + self.fail('finding the doc of {!r} failed'.format(o)) + + for name in ('not__builtin__', 'strrr', 'strr.translate', + 'str.trrrranslate', '__builtin__.strrr', + '__builtin__.str.trrranslate'): + self.assertIsNone(pydoc.locate(name)) + self.assertRaises(ImportError, pydoc.render_doc, name) + def test_main(): test.test_support.run_unittest(PyDocDocTest, @@ -37,6 +37,9 @@ Core and Builtins Library ------- +- Issue #8887: "pydoc somebuiltin.somemethod" (or help('somebuiltin.somemethod') + in Python code) now finds the doc of the method. + - Issue #12603: Fix pydoc.synopsis() on files with non-negative st_mtime. - Issue #12514: Use try/finally to assure the timeit module restores garbage |