mirror of
https://github.com/python/cpython.git
synced 2025-09-19 23:20:25 +00:00
bpo-26120: make pydoc exclude __future__ imports from the data block of the module (GH-30888)
This commit is contained in:
parent
4c116f716b
commit
15ba8167d7
3 changed files with 10 additions and 0 deletions
|
@ -54,6 +54,7 @@ Richard Chamberlain, for the first implementation of textdoc.
|
||||||
# the current directory is changed with os.chdir(), an incorrect
|
# the current directory is changed with os.chdir(), an incorrect
|
||||||
# path will be displayed.
|
# path will be displayed.
|
||||||
|
|
||||||
|
import __future__
|
||||||
import builtins
|
import builtins
|
||||||
import importlib._bootstrap
|
import importlib._bootstrap
|
||||||
import importlib._bootstrap_external
|
import importlib._bootstrap_external
|
||||||
|
@ -274,6 +275,8 @@ def _split_list(s, predicate):
|
||||||
no.append(x)
|
no.append(x)
|
||||||
return yes, no
|
return yes, no
|
||||||
|
|
||||||
|
_future_feature_names = set(__future__.all_feature_names)
|
||||||
|
|
||||||
def visiblename(name, all=None, obj=None):
|
def visiblename(name, all=None, obj=None):
|
||||||
"""Decide whether to show documentation on a variable."""
|
"""Decide whether to show documentation on a variable."""
|
||||||
# Certain special names are redundant or internal.
|
# 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
|
# Namedtuples have public fields and methods with a single leading underscore
|
||||||
if name.startswith('_') and hasattr(obj, '_fields'):
|
if name.startswith('_') and hasattr(obj, '_fields'):
|
||||||
return True
|
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:
|
if all is not None:
|
||||||
# only document that which the programmer exported in __all__
|
# only document that which the programmer exported in __all__
|
||||||
return name in all
|
return name in all
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
"""This is a test module for test_pydoc"""
|
"""This is a test module for test_pydoc"""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import types
|
import types
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
:mod:`pydoc` now excludes __future__ imports from the module's data items.
|
Loading…
Add table
Add a link
Reference in a new issue