Commit c473f8ce authored by Éric Araujo's avatar Éric Araujo

Merge fix for #8887 from 3.2

parents 947fed42 e64e51bf
...@@ -1479,13 +1479,14 @@ def locate(path, forceload=0): ...@@ -1479,13 +1479,14 @@ def locate(path, forceload=0):
else: break else: break
if module: if module:
object = module object = module
for part in parts[n:]:
try: object = getattr(object, part)
except AttributeError: return None
return object
else: else:
if hasattr(builtins, path): object = builtins
return getattr(builtins, path) for part in parts[n:]:
try:
object = getattr(object, part)
except AttributeError:
return None
return object
# --------------------------------------- interactive interpreter interface # --------------------------------------- interactive interpreter interface
......
import os import os
import sys import sys
import builtins
import difflib import difflib
import inspect import inspect
import pydoc import pydoc
...@@ -425,6 +426,23 @@ class TestDescriptions(unittest.TestCase): ...@@ -425,6 +426,23 @@ class TestDescriptions(unittest.TestCase):
expected = 'C in module %s object' % __name__ expected = 'C in module %s object' % __name__
self.assertIn(expected, pydoc.render_doc(c)) self.assertIn(expected, pydoc.render_doc(c))
def test_builtin(self):
for name in ('str', 'str.translate', 'builtins.str',
'builtins.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 ('notbuiltins', 'strrr', 'strr.translate',
'str.trrrranslate', 'builtins.strrr',
'builtins.str.trrranslate'):
self.assertIsNone(pydoc.locate(name))
self.assertRaises(ImportError, pydoc.render_doc, name)
@unittest.skipUnless(threading, 'Threading required for this test.') @unittest.skipUnless(threading, 'Threading required for this test.')
class PydocServerTest(unittest.TestCase): class PydocServerTest(unittest.TestCase):
......
...@@ -244,6 +244,9 @@ Core and Builtins ...@@ -244,6 +244,9 @@ Core and Builtins
Library Library
------- -------
- Issue #8887: "pydoc somebuiltin.somemethod" (or help('somebuiltin.somemethod')
in Python code) now finds the doc of the method.
- Issue #10968: Remove indirection in threading. The public names (Thread, - Issue #10968: Remove indirection in threading. The public names (Thread,
Condition, etc.) used to be factory functions returning instances of hidden Condition, etc.) used to be factory functions returning instances of hidden
classes (_Thread, _Condition, etc.), because (if Guido recalls correctly) this classes (_Thread, _Condition, etc.), because (if Guido recalls correctly) this
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment