diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2022-03-28 21:02:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-28 21:02:57 (GMT) |
commit | 15ba8167d78f9e66bd5b07c4e5cbb0463460310a (patch) | |
tree | a92af838f85ff7917929c1b1b6e7e55566afb219 /Lib/pydoc.py | |
parent | 4c116f716bd1c174d6530b9a7a5ed3863927a109 (diff) | |
download | cpython-15ba8167d78f9e66bd5b07c4e5cbb0463460310a.zip cpython-15ba8167d78f9e66bd5b07c4e5cbb0463460310a.tar.gz cpython-15ba8167d78f9e66bd5b07c4e5cbb0463460310a.tar.bz2 |
bpo-26120: make pydoc exclude __future__ imports from the data block of the module (GH-30888)
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-x | Lib/pydoc.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 85eefa4..7ae3908 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -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 |