cpython: b41404a3f7d4 (original) (raw)
--- a/Doc/library/pydoc.rst
+++ b/Doc/library/pydoc.rst
@@ -63,7 +63,9 @@ documents precisely the version of the m
Python interpreter and typed import spam
.
Module docs for core modules are assumed to reside in
-http://docs.python.org/library/. This can be overridden by setting the
-:envvar:PYTHONDOCS
environment variable to a different URL or to a local
-directory containing the Library Reference Manual pages.
+http://docs.python.org/X.Y/library/
where X
and Y
are the
+major and minor version numbers of the Python interpreter. This can
+be overridden by setting the :envvar:PYTHONDOCS
environment variable
+to a different URL or to a local directory containing the Library
+Reference Manual pages.
--- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -26,13 +26,13 @@ to a file named ".html". Module docs for core modules are assumed to be in
This can be overridden by setting the PYTHONDOCS environment variable to a different URL or to a local directory containing the Library Reference Manual pages. """ - +all = ['help'] author = "Ka-Ping Yee ping@lfw.org" date = "26 February 2001" @@ -54,14 +54,7 @@ Richard Chamberlain, for the first imple import sys, imp, os, re, inspect, builtins, pkgutil from reprlib import Repr from traceback import extract_tb as _extract_tb -try:
Python 2.3 compatibility
- class deque(list):
def popleft(self):[](#l2.28)
return self.pop(0)[](#l2.29)
- +from collections import deque
--------------------------------------------------------- common routines
def pathdirs(): @@ -159,7 +152,8 @@ def visiblename(name, all=None): # Certain special names are redundant. _hidden_names = ('builtins', 'doc', 'file', 'path', 'module', 'name', 'slots', 'package',
'__cached__')[](#l2.39)
'__cached__', '__author__', '__credits__', '__date__',[](#l2.40)
if name in _hidden_names: return 0'__version__')[](#l2.41)
if name.startswith('') and name.endswith(''): return 1 Private names are hidden, but special names are displayed. @@ -306,6 +300,11 @@ def safeimport(path, forceload=0, cache=
---------------------------------------------------- formatter base class
- PYTHONDOCS = os.environ.get("PYTHONDOCS",
"http://docs.python.org/%d.%d/library"[](#l2.51)
% sys.version_info[:2])[](#l2.52)
+ def document(self, object, name=None, *args): """Generate documentation for an object.""" args = (object, name) + args @@ -340,10 +339,10 @@ class Doc: except TypeError: file = '(built-in)'
docloc = os.environ.get("PYTHONDOCS",[](#l2.61)
"http://docs.python.org/library")[](#l2.62)
docloc = os.environ.get("PYTHONDOCS", self.PYTHONDOCS)[](#l2.63)
+ basedir = os.path.join(sys.exec_prefix, "lib",
"python"+sys.version[0:3])[](#l2.66)
"python%d.%d" % sys.version_info[:2])[](#l2.67) if (isinstance(object, type(os)) and[](#l2.68) (object.__name__ in ('errno', 'exceptions', 'gc', 'imp',[](#l2.69) 'marshal', 'posix', 'signal', 'sys',[](#l2.70)
@@ -607,7 +606,7 @@ class HTMLDoc(Doc): head = head + ' (%s)' % ', '.join(info) docloc = self.getdocloc(object) if docloc is not None:
docloc = '<br><a href="%(docloc)s">Module Docs</a>' % locals()[](#l2.75)
docloc = '<br><a href="%(docloc)s">Module Reference</a>' % locals()[](#l2.76) else:[](#l2.77) docloc = ''[](#l2.78) result = self.heading([](#l2.79)
@@ -1016,21 +1015,16 @@ class TextDoc(Doc): name = object.name # ignore the passed-in name synop, desc = splitdoc(getdoc(object)) result = self.section('NAME', name + (synop and ' - ' + synop)) -
try:[](#l2.85)
all = object.__all__[](#l2.86)
except AttributeError:[](#l2.87)
all = None[](#l2.88)
try:[](#l2.90)
file = inspect.getabsfile(object)[](#l2.91)
except TypeError:[](#l2.92)
file = '(built-in)'[](#l2.93)
result = result + self.section('FILE', file)[](#l2.94)
all = getattr(object, '__all__', None)[](#l2.96) docloc = self.getdocloc(object)[](#l2.97) if docloc is not None:[](#l2.98)
result = result + self.section('MODULE DOCS', docloc)[](#l2.99)
result = result + self.section('MODULE REFERENCE', docloc + """[](#l2.100)
+ +The following documentation is automatically generated from the Python source +files. It may be incomplete, incorrect or include features that are considered +implementation detail and may vary between Python implementations. When in +doubt, consult the module reference at the location listed above. +""") if desc: result = result + self.section('DESCRIPTION', desc) @@ -1109,6 +1103,11 @@ class TextDoc(Doc): result = result + self.section('AUTHOR', str(object.author)) if hasattr(object, 'credits'): result = result + self.section('CREDITS', str(object.credits))
try:[](#l2.114)
file = inspect.getabsfile(object)[](#l2.115)
except TypeError:[](#l2.116)
file = '(built-in)'[](#l2.117)
result = result + self.section('FILE', file)[](#l2.118) return result[](#l2.119)
def docclass(self, object, name=None, mod=None):
--- a/Lib/test/pydoc_mod.py +++ b/Lib/test/pydoc_mod.py @@ -3,7 +3,7 @@ author = "Benjamin Peterson" credits = "Nobody" version = "1.2.3.4" - +xyz = "X, Y and Z" class A: """Hello and goodbye"""
--- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -22,9 +22,6 @@ if hasattr(pydoc_mod, "loader"): expected_text_pattern = """ NAME test.pydoc_mod - This is a test module for test_pydoc - -FILE
%s CLASSES builtins.object @@ -72,9 +69,7 @@ FUNCTIONS nodoc_func() DATA
VERSION 1.2.3.4 @@ -84,6 +79,9 @@ AUTHOR CREDITS Nobody + +FILE
""".strip() expected_html_pattern = """ @@ -167,9 +165,7 @@ war Data \x20\x20\x20\x20
-credits = 'Nobody'
-version = '1.2.3.4'