From 7dcb98bde8544a0d2d5d20009423cff6ebd3b385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Thu, 5 Nov 2026 08:58:48 -0300 Subject: [PATCH 1/3] gh-161415: Remove nonexistent related help topics in pydoc The TYPES topic listed FILES, which was removed from Helper.topics in Python 3.4, and the UNICODE topic listed unicode, the Python 2 built-in type. help() finds no entry for either of them. Co-Authored-By: Claude Opus 5.5 --- Lib/pydoc.py | 4 ++-- Lib/test/test_pydoc/test_pydoc.py | 14 ++++++++++++++ .../2026-11-05-12-00-24.gh-issue-161415.NJhrAR.rst | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2026-11-05-12-00-24.gh-issue-161415.NJhrAR.rst diff --git a/Lib/pydoc.py b/Lib/pydoc.py index c0e26efa70e4314..b160e3c4214c328 100644 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -2029,12 +2029,12 @@ class Helper: topics = { 'TYPES': ('types', 'STRINGS UNICODE NUMBERS SEQUENCES MAPPINGS ' - 'FUNCTIONS CLASSES MODULES FILES inspect'), + 'FUNCTIONS CLASSES MODULES inspect'), 'STRINGS': ('strings', 'str UNICODE SEQUENCES STRINGMETHODS ' 'FORMATTING TYPES'), 'STRINGMETHODS': ('string-methods', 'STRINGS FORMATTING'), 'FORMATTING': ('formatstrings', 'OPERATORS'), - 'UNICODE': ('strings', 'encodings unicode SEQUENCES STRINGMETHODS ' + 'UNICODE': ('strings', 'encodings SEQUENCES STRINGMETHODS ' 'FORMATTING TYPES'), 'NUMBERS': ('numbers', 'INTEGER FLOAT COMPLEX TYPES'), 'INTEGER': ('integers', 'int range'), diff --git a/Lib/test/test_pydoc/test_pydoc.py b/Lib/test/test_pydoc/test_pydoc.py index 896d961defe09df..5b65a1035e202d7 100644 --- a/Lib/test/test_pydoc/test_pydoc.py +++ b/Lib/test/test_pydoc/test_pydoc.py @@ -2294,6 +2294,20 @@ def test_keywords(self): self.assertEqual(sorted(pydoc.Helper.keywords), sorted(keyword.kwlist + ['case', 'match', 'lazy'])) + def test_related_topics(self): + # Every related help topic must be something help() can document. + helper = pydoc.Helper + for name, target in (*helper.topics.items(), *helper.keywords.items()): + if not isinstance(target, tuple): + continue + for xref in target[1].split(): + with self.subTest(topic=name, xref=xref): + self.assertTrue(xref in helper.topics + or xref in helper.keywords + or xref in helper.symbols + or xref == 'keywords' # the keyword list + or pydoc.locate(xref) is not None) + def test_interact_empty_line_continues(self): # gh-138568: test pressing Enter without input should continue in help session self.assertEqual( diff --git a/Misc/NEWS.d/next/Library/2026-11-05-12-00-24.gh-issue-161415.NJhrAR.rst b/Misc/NEWS.d/next/Library/2026-11-05-12-00-24.gh-issue-161415.NJhrAR.rst new file mode 100644 index 000000000000000..22cc4665c253dde --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-11-05-12-00-24.gh-issue-161415.NJhrAR.rst @@ -0,0 +1,3 @@ +Remove ``FILES`` and ``unicode`` from the related help topics listed by +:func:`help` for the ``TYPES`` and ``UNICODE`` topics. Neither exists in +Python 3, so asking for help on them failed. From 92a81740012f41b3bb7e59f2ac7fcca5003153ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Thu, 5 Nov 2026 19:05:06 -0300 Subject: [PATCH 2/3] Check related help topics through help() output Co-Authored-By: Claude Opus 5.5 --- Lib/test/test_pydoc/test_pydoc.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_pydoc/test_pydoc.py b/Lib/test/test_pydoc/test_pydoc.py index 5b65a1035e202d7..a8e1026da85e207 100644 --- a/Lib/test/test_pydoc/test_pydoc.py +++ b/Lib/test/test_pydoc/test_pydoc.py @@ -2296,17 +2296,15 @@ def test_keywords(self): def test_related_topics(self): # Every related help topic must be something help() can document. - helper = pydoc.Helper - for name, target in (*helper.topics.items(), *helper.keywords.items()): + for name, target in (*pydoc.Helper.topics.items(), + *pydoc.Helper.keywords.items()): if not isinstance(target, tuple): continue for xref in target[1].split(): with self.subTest(topic=name, xref=xref): - self.assertTrue(xref in helper.topics - or xref in helper.keywords - or xref in helper.symbols - or xref == 'keywords' # the keyword list - or pydoc.locate(xref) is not None) + buf = StringIO() + pydoc.Helper(output=buf).help(xref) + self.assertNotIn('No help entry found', buf.getvalue()) def test_interact_empty_line_continues(self): # gh-138568: test pressing Enter without input should continue in help session From 65767db71e49c2c88f4d95ca4a3db6a4dcc58633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Fri, 6 Nov 2026 21:25:17 -0300 Subject: [PATCH 3/3] Also check the targets of help topic aliases Co-Authored-By: Claude Opus 5.5 --- Lib/test/test_pydoc/test_pydoc.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_pydoc/test_pydoc.py b/Lib/test/test_pydoc/test_pydoc.py index 9c1f3c7a95828aa..552b0c7d0759498 100644 --- a/Lib/test/test_pydoc/test_pydoc.py +++ b/Lib/test/test_pydoc/test_pydoc.py @@ -2295,11 +2295,12 @@ def test_keywords(self): sorted(keyword.kwlist + ['case', 'match', 'lazy'])) def test_related_topics(self): - # Every related help topic must be something help() can document. + # Every related help topic and alias must be something help() can + # document. for name, target in (*pydoc.Helper.topics.items(), *pydoc.Helper.keywords.items()): - if not isinstance(target, tuple): - continue + if isinstance(target, str): + target = ('', target) for xref in target[1].split(): with self.subTest(topic=name, xref=xref): buf = StringIO()