bpo-35614: Fix pydoc help() on metaclasses (#11357)

https://github.com/python/cpython/commit/b539cef31c060c7eecc331d25a23b80ded0... commit: b539cef31c060c7eecc331d25a23b80ded0baf08 branch: master author: Sanyam Khurana <8039608+CuriousLearner@users.noreply.github.com> committer: Nick Coghlan <ncoghlan@gmail.com> date: 2018-12-31T15:14:47+10:00 summary: bpo-35614: Fix pydoc help() on metaclasses (#11357) files: A Misc/NEWS.d/next/Library/2018-12-30-01-10-50.bpo-35614.cnkM4f.rst M Lib/pydoc.py M Lib/test/test_pydoc.py diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 1d84b847cf9f..59f6e3935135 100644 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1255,7 +1255,7 @@ def makename(c, m=object.__module__): # List the built-in subclasses, if any: subclasses = sorted( - (str(cls.__name__) for cls in object.__subclasses__() + (str(cls.__name__) for cls in type.__subclasses__(object) if not cls.__name__.startswith("_") and cls.__module__ == "builtins"), key=str.lower ) diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index 409fea4a5e94..c58a8b13e76d 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -636,6 +636,17 @@ class ZeroDivisionError(ArithmeticError) # Testing that the subclasses section does not appear self.assertNotIn('Built-in subclasses', text) + def test_builtin_on_metaclasses(self): + """Tests help on metaclasses. + + When running help() on a metaclasses such as type, it + should not contain any "Built-in subclasses" section. + """ + doc = pydoc.TextDoc() + text = doc.docclass(type) + # Testing that the subclasses section does not appear + self.assertNotIn('Built-in subclasses', text) + @unittest.skipIf(sys.flags.optimize >= 2, 'Docstrings are omitted with -O2 and above') @unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(), diff --git a/Misc/NEWS.d/next/Library/2018-12-30-01-10-50.bpo-35614.cnkM4f.rst b/Misc/NEWS.d/next/Library/2018-12-30-01-10-50.bpo-35614.cnkM4f.rst new file mode 100644 index 000000000000..4d6beffa2be6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-12-30-01-10-50.bpo-35614.cnkM4f.rst @@ -0,0 +1 @@ +Fixed help() on metaclasses. Patch by Sanyam Khurana.
participants (1)
-
Nick Coghlan