Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ead9bfc

Browse files
committed
#16484: Fix pydoc doc links to modules whose names are mixed case.
Patch by Sean Rodman, test by Kaushik N.
1 parent 369826a commit ead9bfc

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

Lib/pydoc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def safeimport(path, forceload=0, cache={}):
354354
class Doc:
355355

356356
PYTHONDOCS = os.environ.get("PYTHONDOCS",
357-
"http://docs.python.org/%d.%d/library"
357+
"https://docs.python.org/%d.%d/library"
358358
% sys.version_info[:2])
359359

360360
def document(self, object, name=None, *args):
@@ -383,7 +383,9 @@ def fail(self, object, name=None, *args):
383383

384384
docmodule = docclass = docroutine = docother = docproperty = docdata = fail
385385

386-
def getdocloc(self, object):
386+
def getdocloc(self, object,
387+
basedir=os.path.join(sys.base_exec_prefix, "lib",
388+
"python%d.%d" % sys.version_info[:2])):
387389
"""Return the location of module docs or None"""
388390

389391
try:
@@ -393,8 +395,6 @@ def getdocloc(self, object):
393395

394396
docloc = os.environ.get("PYTHONDOCS", self.PYTHONDOCS)
395397

396-
basedir = os.path.join(sys.base_exec_prefix, "lib",
397-
"python%d.%d" % sys.version_info[:2])
398398
if (isinstance(object, type(os)) and
399399
(object.__name__ in ('errno', 'exceptions', 'gc', 'imp',
400400
'marshal', 'posix', 'signal', 'sys',
@@ -403,9 +403,9 @@ def getdocloc(self, object):
403403
not file.startswith(os.path.join(basedir, 'site-packages')))) and
404404
object.__name__ not in ('xml.etree', 'test.pydoc_mod')):
405405
if docloc.startswith("http://"):
406-
docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__)
406+
docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__.lower())
407407
else:
408-
docloc = os.path.join(docloc, object.__name__ + ".html")
408+
docloc = os.path.join(docloc, object.__name__.lower() + ".html")
409409
else:
410410
docloc = None
411411
return docloc

Lib/test/test_pydoc.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import unittest
1919
import urllib.parse
2020
import xml.etree
21+
import xml.etree.ElementTree
2122
import textwrap
2223
from io import StringIO
2324
from collections import namedtuple
@@ -352,6 +353,14 @@ def get_pydoc_html(module):
352353
loc = "<br><a href=\"" + loc + "\">Module Docs</a>"
353354
return output.strip(), loc
354355

356+
def get_pydoc_link(module):
357+
"Returns a documentation web link of a module"
358+
dirname = os.path.dirname
359+
basedir = os.path.join(dirname(dirname(__file__)))
360+
doc = pydoc.TextDoc()
361+
loc = doc.getdocloc(module, basedir=basedir)
362+
return loc
363+
355364
def get_pydoc_text(module):
356365
"Returns pydoc generated output as text"
357366
doc = pydoc.TextDoc()
@@ -443,6 +452,11 @@ class BinaryInteger(enum.IntEnum):
443452
doc = pydoc.render_doc(BinaryInteger)
444453
self.assertIn('<BinaryInteger.zero: 0>', doc)
445454

455+
def test_mixed_case_module_names_are_lower_cased(self):
456+
# issue16484
457+
doc_link = get_pydoc_link(xml.etree.ElementTree)
458+
self.assertIn('xml.etree.elementtree', doc_link)
459+
446460
def test_issue8225(self):
447461
# Test issue8225 to ensure no doc link appears for xml.etree
448462
result, doc_loc = get_pydoc_text(xml.etree)

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,7 @@ Louis Munro
10181018
R. David Murray
10191019
Matti Mäki
10201020
Jörg Müller
1021+
Kaushik N
10211022
Dale Nagata
10221023
John Nagle
10231024
Takahiro Nakayama

0 commit comments

Comments
 (0)