Skip to content

Commit 63f32fa

Browse files
authored
bpo-26120: do not exclude __future__ import in pydoc of the __future__ module itself (GH-32180)
1 parent a5ba445 commit 63f32fa

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Lib/pydoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def visiblename(name, all=None, obj=None):
292292
if name.startswith('_') and hasattr(obj, '_fields'):
293293
return True
294294
# Ignore __future__ imports.
295-
if name in _future_feature_names:
295+
if obj is not __future__ and name in _future_feature_names:
296296
if isinstance(getattr(obj, name, None), __future__._Feature):
297297
return False
298298
if all is not None:

Lib/test/test_pydoc.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,23 @@ class B(A)
850850
for expected_line in expected_lines:
851851
self.assertIn(expected_line, as_text)
852852

853+
def test__future__imports(self):
854+
# __future__ features are excluded from module help,
855+
# except when it's the __future__ module itself
856+
import __future__
857+
future_text, _ = get_pydoc_text(__future__)
858+
future_html, _ = get_pydoc_html(__future__)
859+
pydoc_mod_text, _ = get_pydoc_text(pydoc_mod)
860+
pydoc_mod_html, _ = get_pydoc_html(pydoc_mod)
861+
862+
for feature in __future__.all_feature_names:
863+
txt = f"{feature} = _Feature"
864+
html = f"<strong>{feature}</strong> = _Feature"
865+
self.assertIn(txt, future_text)
866+
self.assertIn(html, future_html)
867+
self.assertNotIn(txt, pydoc_mod_text)
868+
self.assertNotIn(html, pydoc_mod_html)
869+
853870

854871
class PydocImportTest(PydocBaseTest):
855872

0 commit comments

Comments
 (0)