[Python-checkins] bpo-26120: make pydoc exclude __future__ imports from the data block of the module (GH-30888)

iritkatriel webhook-mailer at python.org
Mon Mar 28 17:03:13 EDT 2022


https://github.com/python/cpython/commit/15ba8167d78f9e66bd5b07c4e5cbb0463460310a
commit: 15ba8167d78f9e66bd5b07c4e5cbb0463460310a
branch: main
author: Irit Katriel <1055913+iritkatriel at users.noreply.github.com>
committer: iritkatriel <1055913+iritkatriel at users.noreply.github.com>
date: 2022-03-28T22:02:57+01:00
summary:

bpo-26120: make pydoc exclude __future__ imports from the data block of the module (GH-30888)

files:
A Misc/NEWS.d/next/Library/2022-01-25-15-45-04.bpo-26120.YzrBMO.rst
M Lib/pydoc.py
M Lib/test/pydoc_mod.py

diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 85eefa46b7299..7ae390852fa01 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -54,6 +54,7 @@ class or function within a module or module in a package.  If the
 #     the current directory is changed with os.chdir(), an incorrect
 #     path will be displayed.
 
+import __future__
 import builtins
 import importlib._bootstrap
 import importlib._bootstrap_external
@@ -274,6 +275,8 @@ def _split_list(s, predicate):
             no.append(x)
     return yes, no
 
+_future_feature_names = set(__future__.all_feature_names)
+
 def visiblename(name, all=None, obj=None):
     """Decide whether to show documentation on a variable."""
     # Certain special names are redundant or internal.
@@ -288,6 +291,10 @@ def visiblename(name, all=None, obj=None):
     # Namedtuples have public fields and methods with a single leading underscore
     if name.startswith('_') and hasattr(obj, '_fields'):
         return True
+    # Ignore __future__ imports.
+    if name in _future_feature_names:
+        if isinstance(getattr(obj, name, None), __future__._Feature):
+            return False
     if all is not None:
         # only document that which the programmer exported in __all__
         return name in all
diff --git a/Lib/test/pydoc_mod.py b/Lib/test/pydoc_mod.py
index f9bc4b89d3d0a..80c287fb10c31 100644
--- a/Lib/test/pydoc_mod.py
+++ b/Lib/test/pydoc_mod.py
@@ -1,5 +1,7 @@
 """This is a test module for test_pydoc"""
 
+from __future__ import print_function
+
 import types
 import typing
 
diff --git a/Misc/NEWS.d/next/Library/2022-01-25-15-45-04.bpo-26120.YzrBMO.rst b/Misc/NEWS.d/next/Library/2022-01-25-15-45-04.bpo-26120.YzrBMO.rst
new file mode 100644
index 0000000000000..bc45b277d8d6f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-01-25-15-45-04.bpo-26120.YzrBMO.rst
@@ -0,0 +1 @@
+:mod:`pydoc` now excludes __future__ imports from the module's data items.



More information about the Python-checkins mailing list