Merge pull request #7955 from peterbell10/alias-deprecation-message

Improve warning message from deprecated_alias
This commit is contained in:
Takeshi KOMIYA 2020-07-17 00:22:32 +09:00 committed by GitHub
commit d7d14f20cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 133 additions and 26 deletions

View File

@ -27,7 +27,14 @@ deprecated_alias('sphinx.builders.applehelp',
'AppleHelpIndexerFailed': AppleHelpIndexerFailed,
'AppleHelpBuilder': AppleHelpBuilder,
},
RemovedInSphinx40Warning)
RemovedInSphinx40Warning,
{
'AppleHelpCodeSigningFailed':
'sphinxcontrib.applehelp.AppleHelpCodeSigningFailed',
'AppleHelpIndexerFailed':
'sphinxcontrib.applehelp.AppleHelpIndexerFailed',
'AppleHelpBuilder': 'sphinxcontrib.applehelp.AppleHelpBuilder',
})
def setup(app: Sphinx) -> Dict[str, Any]:

View File

@ -23,7 +23,10 @@ deprecated_alias('sphinx.builders.devhelp',
{
'DevhelpBuilder': DevhelpBuilder,
},
RemovedInSphinx40Warning)
RemovedInSphinx40Warning,
{
'DevhelpBuilder': 'sphinxcontrib.devhelp.DevhelpBuilder'
})
def setup(app: Sphinx) -> Dict[str, Any]:

View File

@ -49,9 +49,12 @@ class DirectoryHTMLBuilder(StandaloneHTMLBuilder):
# for compatibility
deprecated_alias('sphinx.builders.html',
{
'DirectoryHTMLBuilder': DirectoryHTMLBuilder,
'DirectoryHTMLBuilder': DirectoryHTMLBuilder,
},
RemovedInSphinx40Warning)
RemovedInSphinx40Warning,
{
'DirectoryHTMLBuilder': 'sphinx.builders.dirhtml.DirectoryHTMLBuilder',
})
def setup(app: Sphinx) -> Dict[str, Any]:

View File

@ -24,10 +24,17 @@ deprecated_alias('sphinx.builders.htmlhelp',
{
'chm_locales': chm_locales,
'chm_htmlescape': chm_htmlescape,
'HTMLHelpBuilder': HTMLHelpBuilder,
'HTMLHelpBuilder': HTMLHelpBuilder,
'default_htmlhelp_basename': default_htmlhelp_basename,
},
RemovedInSphinx40Warning)
RemovedInSphinx40Warning,
{
'chm_locales': 'sphinxcontrib.htmlhelp.chm_locales',
'chm_htmlescape': 'sphinxcontrib.htmlhelp.chm_htmlescape',
'HTMLHelpBuilder': 'sphinxcontrib.htmlhelp.HTMLHelpBuilder',
'default_htmlhelp_basename':
'sphinxcontrib.htmlhelp.default_htmlhelp_basename',
})
def setup(app: Sphinx) -> Dict[str, Any]:

View File

@ -23,7 +23,11 @@ deprecated_alias('sphinx.builders.qthelp',
'render_file': render_file,
'QtHelpBuilder': QtHelpBuilder,
},
RemovedInSphinx40Warning)
RemovedInSphinx40Warning,
{
'render_file': 'sphinxcontrib.qthelp.render_file',
'QtHelpBuilder': 'sphinxcontrib.qthelp.QtHelpBuilder',
})
def setup(app: Sphinx) -> Dict[str, Any]:

View File

@ -193,7 +193,11 @@ deprecated_alias('sphinx.builders.html',
{
'SingleFileHTMLBuilder': SingleFileHTMLBuilder,
},
RemovedInSphinx40Warning)
RemovedInSphinx40Warning,
{
'SingleFileHTMLBuilder':
'sphinx.builders.singlehtml.SingleFileHTMLBuilder',
})
def setup(app: Sphinx) -> Dict[str, Any]:

View File

@ -29,27 +29,39 @@ class RemovedInSphinx50Warning(PendingDeprecationWarning):
RemovedInNextVersionWarning = RemovedInSphinx40Warning
def deprecated_alias(modname: str, objects: Dict, warning: "Type[Warning]") -> None:
def deprecated_alias(modname: str, objects: Dict[str, object],
warning: "Type[Warning]", names: Dict[str, str] = None) -> None:
module = import_module(modname)
sys.modules[modname] = _ModuleWrapper(module, modname, objects, warning) # type: ignore
sys.modules[modname] = _ModuleWrapper( # type: ignore
module, modname, objects, warning, names)
class _ModuleWrapper:
def __init__(self, module: Any, modname: str, objects: Dict, warning: "Type[Warning]"
) -> None:
def __init__(self, module: Any, modname: str,
objects: Dict[str, object],
warning: "Type[Warning]",
names: Dict[str, str]) -> None:
self._module = module
self._modname = modname
self._objects = objects
self._warning = warning
self._names = names
def __getattr__(self, name: str) -> Any:
if name in self._objects:
warnings.warn("%s.%s is deprecated. Check CHANGES for Sphinx "
"API modifications." % (self._modname, name),
self._warning, stacklevel=3)
return self._objects[name]
if name not in self._objects:
return getattr(self._module, name)
return getattr(self._module, name)
canonical_name = self._names.get(name, None)
if canonical_name is not None:
warnings.warn(
"The alias '{}.{}' is deprecated, use '{}' instead. Check CHANGES for "
"Sphinx API modifications.".format(self._modname, name, canonical_name),
self._warning, stacklevel=3)
else:
warnings.warn("{}.{} is deprecated. Check CHANGES for Sphinx "
"API modifications.".format(self._modname, name),
self._warning, stacklevel=3)
return self._objects[name]
class DeprecatedDict(dict):

View File

@ -298,13 +298,35 @@ deprecated_alias('sphinx.directives',
'Figure': Figure,
'Meta': Meta,
},
RemovedInSphinx40Warning)
RemovedInSphinx40Warning,
{
'Highlight': 'sphinx.directives.code.Highlight',
'CodeBlock': 'sphinx.directives.code.CodeBlock',
'LiteralInclude': 'sphinx.directives.code.LiteralInclude',
'TocTree': 'sphinx.directives.other.TocTree',
'Author': 'sphinx.directives.other.Author',
'Index': 'sphinx.directives.other.IndexDirective',
'VersionChange': 'sphinx.directives.other.VersionChange',
'SeeAlso': 'sphinx.directives.other.SeeAlso',
'TabularColumns': 'sphinx.directives.other.TabularColumns',
'Centered': 'sphinx.directives.other.Centered',
'Acks': 'sphinx.directives.other.Acks',
'HList': 'sphinx.directives.other.HList',
'Only': 'sphinx.directives.other.Only',
'Include': 'sphinx.directives.other.Include',
'Class': 'sphinx.directives.other.Class',
'Figure': 'sphinx.directives.patches.Figure',
'Meta': 'sphinx.directives.patches.Meta',
})
deprecated_alias('sphinx.directives',
{
'DescDirective': ObjectDescription,
},
RemovedInSphinx50Warning)
RemovedInSphinx50Warning,
{
'DescDirective': 'sphinx.directives.ObjectDescription',
})
def setup(app: "Sphinx") -> Dict[str, Any]:

View File

@ -368,7 +368,10 @@ deprecated_alias('sphinx.directives.other',
{
'Index': IndexDirective,
},
RemovedInSphinx40Warning)
RemovedInSphinx40Warning,
{
'Index': 'sphinx.domains.index.IndexDirective',
})
def setup(app: "Sphinx") -> Dict[str, Any]:

View File

@ -194,4 +194,11 @@ deprecated_alias('sphinx.ext.autodoc.importer',
'MockLoader': MockLoader,
'mock': mock,
},
RemovedInSphinx40Warning)
RemovedInSphinx40Warning,
{
'_MockModule': 'sphinx.ext.autodoc.mock._MockModule',
'_MockObject': 'sphinx.ext.autodoc.mock._MockObject',
'MockFinder': 'sphinx.ext.autodoc.mock.MockFinder',
'MockLoader': 'sphinx.ext.autodoc.mock.MockLoader',
'mock': 'sphinx.ext.autodoc.mock.mock',
})

View File

@ -229,4 +229,8 @@ deprecated_alias('sphinx.io',
'FiletypeNotFoundError': FiletypeNotFoundError,
'get_filetype': get_filetype,
},
RemovedInSphinx40Warning)
RemovedInSphinx40Warning,
{
'FiletypeNotFoundError': 'sphinx.errors.FiletypeNotFoundError',
'get_filetype': 'sphinx.util.get_filetype',
})

View File

@ -410,7 +410,13 @@ deprecated_alias('sphinx.transforms',
'CitationReferences': CitationReferenceTransform,
'SmartQuotesSkipper': CitationDefinitionTransform,
},
RemovedInSphinx40Warning)
RemovedInSphinx40Warning,
{
'CitationReferences':
'sphinx.domains.citation.CitationReferenceTransform',
'SmartQuotesSkipper':
'sphinx.domains.citation.CitationDefinitionTransform',
})
def setup(app: "Sphinx") -> Dict[str, Any]:

View File

@ -99,4 +99,12 @@ deprecated_alias('sphinx.util.pycompat',
'sys_encoding': sys.getdefaultencoding(),
'u': '',
},
RemovedInSphinx40Warning)
RemovedInSphinx40Warning,
{
'NoneType': 'sphinx.util.typing.NoneType',
'TextIOWrapper': 'io.TextIOWrapper',
'htmlescape': 'html.escape',
'indent': 'textwrap.indent',
'terminal_safe': 'sphinx.util.console.terminal_safe',
'sys_encoding': 'sys.getdefaultencoding',
})

View File

@ -2140,7 +2140,24 @@ deprecated_alias('sphinx.writers.latex',
'XELATEX_GREEK_DEFAULT_FONTPKG': constants.XELATEX_GREEK_DEFAULT_FONTPKG,
'ExtBabel': ExtBabel,
},
RemovedInSphinx40Warning)
RemovedInSphinx40Warning,
{
'ADDITIONAL_SETTINGS':
'sphinx.builders.latex.constants.ADDITIONAL_SETTINGS',
'DEFAULT_SETTINGS':
'sphinx.builders.latex.constants.DEFAULT_SETTINGS',
'LUALATEX_DEFAULT_FONTPKG':
'sphinx.builders.latex.constants.LUALATEX_DEFAULT_FONTPKG',
'PDFLATEX_DEFAULT_FONTPKG':
'sphinx.builders.latex.constants.PDFLATEX_DEFAULT_FONTPKG',
'SHORTHANDOFF':
'sphinx.builders.latex.constants.SHORTHANDOFF',
'XELATEX_DEFAULT_FONTPKG':
'sphinx.builders.latex.constants.XELATEX_DEFAULT_FONTPKG',
'XELATEX_GREEK_DEFAULT_FONTPKG':
'sphinx.builders.latex.constants.XELATEX_GREEK_DEFAULT_FONTPKG',
'ExtBabel': 'sphinx.builders.latex.util.ExtBabel',
})
# FIXME: Workaround to avoid circular import
# refs: https://github.com/sphinx-doc/sphinx/issues/5433