]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-35614: Fix pydoc help() on metaclasses (#11357)
authorSanyam Khurana <8039608+CuriousLearner@users.noreply.github.com>
Mon, 31 Dec 2018 05:14:47 +0000 (10:44 +0530)
committerNick Coghlan <ncoghlan@gmail.com>
Mon, 31 Dec 2018 05:14:47 +0000 (15:14 +1000)
Lib/pydoc.py
Lib/test/test_pydoc.py
Misc/NEWS.d/next/Library/2018-12-30-01-10-50.bpo-35614.cnkM4f.rst [new file with mode: 0644]

index 1d84b847cf9f780cf436b987b2f978b90aba850f..59f6e393513533b6816831764ed24b82f688a7fd 100644 (file)
@@ -1255,7 +1255,7 @@ location listed above.
 
         # 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
         )
index 409fea4a5e944a0829d706a6e06ee207da9a891d..c58a8b13e76de1e489011ba3cef627dd012d9521 100644 (file)
@@ -636,6 +636,17 @@ class PydocDocTest(unittest.TestCase):
         # 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 (file)
index 0000000..4d6beff
--- /dev/null
@@ -0,0 +1 @@
+Fixed help() on metaclasses. Patch by Sanyam Khurana.