8000 bpo-26120: make pydoc exclude __future__ imports from the data block … · python/cpython@15ba816 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 15ba816

Browse files
authored
bpo-26120: make pydoc exclude __future__ imports from the data block of the module (GH-30888)
1 parent 4c116f7 commit 15ba816

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

Lib/pydoc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class or function within a module or module in a package. If the
5454
# the current directory is changed with os.chdir(), an incorrect
5555
# path will be displayed.
5656

57+
import __future__
5758
import builtins
5859
import importlib._bootstrap
5960
import importlib._bootstrap_external
@@ -274,6 +275,8 @@ def _split_list(s, predicate):
274275
no.append(x)
275276
return yes, no
276277

278+
_future_feature_names = set(__future__.all_feature_names)
279+
277280
def visiblename(name, all=None, obj=None):
278281
"""Decide whether to show documentation on a variable."""
279282
# Certain special names are redundant or internal.
@@ -288,6 +291,10 @@ def visiblename(name, all=None, obj=None):
288291
# Namedtuples have public fields and methods with a single leading underscore
289292
if name.startswith('_') and hasattr(obj, '_fields'):
290293
return True
294+
# Ignore __future__ imports.
295+
if name in _future_feature_names:
296+
if isinstance(getattr(obj, name, None), __future__._Feature):
297+
return False
291298
if all is not None:
292299
# only document that which the programmer exported in __all__
293300
return name in all

Lib/test/pydoc_mod.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""This is a test module for test_pydoc"""
22

3+
from __future__ import print_function
4+
35
import types
46
import typing
57

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:mod:`pydoc` now excludes __future__ imports from the module's data items.

0 commit comments

Comments
 (0)
0