[Python-checkins] bpo-26120: do not exclude __future__ import in pydoc of the __future__ module itself (GH-32180)

iritkatriel webhook-mailer at python.org
Tue Mar 29 18:07:24 EDT 2022


https://github.com/python/cpython/commit/63f32fae79e16e6dc71777bd3fcb623b2c3ff742
commit: 63f32fae79e16e6dc71777bd3fcb623b2c3ff742
branch: main
author: Irit Katriel <1055913+iritkatriel at users.noreply.github.com>
committer: iritkatriel <1055913+iritkatriel at users.noreply.github.com>
date: 2022-03-29T23:07:15+01:00
summary:

bpo-26120: do not exclude __future__ import in pydoc of the __future__ module itself (GH-32180)

files:
M Lib/pydoc.py
M Lib/test/test_pydoc.py

diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 7ae390852fa01..18b476ee660dc 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -292,7 +292,7 @@ def visiblename(name, all=None, obj=None):
     if name.startswith('_') and hasattr(obj, '_fields'):
         return True
     # Ignore __future__ imports.
-    if name in _future_feature_names:
+    if obj is not __future__ and name in _future_feature_names:
         if isinstance(getattr(obj, name, None), __future__._Feature):
             return False
     if all is not None:
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py
index e2dab1207172d..9c900c3e8ee0a 100644
--- a/Lib/test/test_pydoc.py
+++ b/Lib/test/test_pydoc.py
@@ -850,6 +850,23 @@ class B(A)
         for expected_line in expected_lines:
             self.assertIn(expected_line, as_text)
 
+    def test__future__imports(self):
+        # __future__ features are excluded from module help,
+        # except when it's the __future__ module itself
+        import __future__
+        future_text, _ = get_pydoc_text(__future__)
+        future_html, _ = get_pydoc_html(__future__)
+        pydoc_mod_text, _ = get_pydoc_text(pydoc_mod)
+        pydoc_mod_html, _ = get_pydoc_html(pydoc_mod)
+
+        for feature in __future__.all_feature_names:
+            txt = f"{feature} = _Feature"
+            html = f"<strong>{feature}</strong> = _Feature"
+            self.assertIn(txt, future_text)
+            self.assertIn(html, future_html)
+            self.assertNotIn(txt, pydoc_mod_text)
+            self.assertNotIn(html, pydoc_mod_html)
+
 
 class PydocImportTest(PydocBaseTest):
 



More information about the Python-checkins mailing list