]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-26120: make pydoc exclude __future__ imports from the data block of the module...
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Mon, 28 Mar 2022 21:02:57 +0000 (22:02 +0100)
committerGitHub <noreply@github.com>
Mon, 28 Mar 2022 21:02:57 +0000 (22:02 +0100)
Lib/pydoc.py
Lib/test/pydoc_mod.py
Misc/NEWS.d/next/Library/2022-01-25-15-45-04.bpo-26120.YzrBMO.rst [new file with mode: 0644]

index 85eefa46b7299e452bcdcc318380cc1869aa69c9..7ae390852fa01bb723974cfc12adc2d6e6513d38 100755 (executable)
@@ -54,6 +54,7 @@ Richard Chamberlain, for the first implementation of textdoc.
 #     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
index f9bc4b89d3d0a46086d12c2cf1481eb26587ab3b..80c287fb10c31e79bc7211cdaa1152f219b05fc4 100644 (file)
@@ -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 (file)
index 0000000..bc45b27
--- /dev/null
@@ -0,0 +1 @@
+:mod:`pydoc` now excludes __future__ imports from the module's data items.