Fix #5471: Show appropriate warning for deprecated APIs

This commit is contained in:
Takeshi KOMIYA 2018-10-15 00:33:19 +09:00
parent c584b71b12
commit 257394a459
32 changed files with 114 additions and 113 deletions

View File

@ -13,6 +13,8 @@ Deprecated
Features added
--------------
* #5471: Show appropriate deprecation warnings
Bugs fixed
----------

View File

@ -31,8 +31,7 @@ if False:
# by default, all DeprecationWarning under sphinx package will be emit.
# Users can avoid this by using environment variable: PYTHONWARNINGS=
if 'PYTHONWARNINGS' not in os.environ:
warnings.filterwarnings('default',
category=RemovedInNextVersionWarning, module='sphinx')
warnings.filterwarnings('default', category=RemovedInNextVersionWarning)
# docutils.io using mode='rU' for open
warnings.filterwarnings('ignore', "'U' mode is deprecated",
DeprecationWarning, module='docutils.io')

View File

@ -205,7 +205,7 @@ class math(nodes.math):
if key == 'latex' and 'latex' not in self.attributes:
warnings.warn("math node for Sphinx was replaced by docutils'. "
"Therefore please use ``node.astext()`` to get an equation instead.",
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return self.astext()
else:
return nodes.math.__getitem__(self, key)
@ -224,7 +224,7 @@ class math_block(nodes.math_block):
if key == 'latex' and 'latex' not in self.attributes:
warnings.warn("displaymath node for Sphinx was replaced by docutils'. "
"Therefore please use ``node.astext()`` to get an equation instead.",
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return self.astext()
else:
return nodes.math_block.__getitem__(self, key)

View File

@ -385,7 +385,7 @@ class Sphinx(object):
Use :mod:`sphinx.util.logging` instead.
"""
warnings.warn('app.warning() is now deprecated. Use sphinx.util.logging instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
logger.warning(message, type=type, subtype=subtype, location=location)
def info(self, message='', nonl=False):
@ -399,7 +399,7 @@ class Sphinx(object):
Use :mod:`sphinx.util.logging` instead.
"""
warnings.warn('app.info() is now deprecated. Use sphinx.util.logging instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
logger.info(message, nonl=nonl)
def verbose(self, message, *args, **kwargs):
@ -410,7 +410,7 @@ class Sphinx(object):
Use :mod:`sphinx.util.logging` instead.
"""
warnings.warn('app.verbose() is now deprecated. Use sphinx.util.logging instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
logger.verbose(message, *args, **kwargs)
def debug(self, message, *args, **kwargs):
@ -421,7 +421,7 @@ class Sphinx(object):
Use :mod:`sphinx.util.logging` instead.
"""
warnings.warn('app.debug() is now deprecated. Use sphinx.util.logging instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
logger.debug(message, *args, **kwargs)
def debug2(self, message, *args, **kwargs):
@ -432,7 +432,7 @@ class Sphinx(object):
Use :mod:`sphinx.util.logging` instead.
"""
warnings.warn('app.debug2() is now deprecated. Use debug() instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
logger.debug(message, *args, **kwargs)
# ---- general extensibility interface -------------------------------------
@ -470,7 +470,7 @@ class Sphinx(object):
"""
warnings.warn('app.import_object() is deprecated. '
'Use sphinx.util.add_object_type() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return import_object(objname, source=None)
# event interface
@ -663,7 +663,7 @@ class Sphinx(object):
# type: () -> Dict[nodes.Node, Tuple[unicode, TitleGetter]]
warnings.warn('app.enumerable_nodes() is deprecated. '
'Use app.get_domain("std").enumerable_nodes instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return self.registry.enumerable_nodes
def add_directive(self, name, obj, content=None, arguments=None, override=False, **options): # NOQA
@ -801,7 +801,7 @@ class Sphinx(object):
"""
warnings.warn('app.override_domain() is deprecated. '
'Use app.add_domain() with override option instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
self.registry.add_domain(domain, override=True)
def add_directive_to_domain(self, domain, name, obj, has_content=None, argument_spec=None,
@ -924,7 +924,7 @@ class Sphinx(object):
"""
warnings.warn('app.add_description_unit() is now deprecated. '
'Use app.add_object_type() instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
self.add_object_type(directivename, rolename, indextemplate, parse_node,
ref_nodeclass, objname, doc_field_types)
@ -1013,7 +1013,7 @@ class Sphinx(object):
"""An alias of :meth:`add_js_file`."""
warnings.warn('The app.add_javascript() is deprecated. '
'Please use app.add_js_file() instead.',
RemovedInSphinx40Warning)
RemovedInSphinx40Warning, stacklevel=2)
self.add_js_file(filename, **kwargs)
def add_js_file(self, filename, **kwargs):
@ -1088,7 +1088,7 @@ class Sphinx(object):
"""An alias of :meth:`add_css_file`."""
warnings.warn('The app.add_stylesheet() is deprecated. '
'Please use app.add_css_file() instead.',
RemovedInSphinx40Warning)
RemovedInSphinx40Warning, stacklevel=2)
attributes = {} # type: Dict[unicode, unicode]
if alternate:

View File

@ -150,7 +150,7 @@ class Builder(object):
warnings.warn('builder.translator_class() is now deprecated. '
'Please use builder.create_translator() and '
'builder.default_translator_class instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
return None
return self.create_translator

View File

@ -109,7 +109,7 @@ class CSSContainer(list):
# type: (int, Union[unicode, Stylesheet]) -> None
warnings.warn('builder.css_files is deprecated. '
'Please use app.add_stylesheet() instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
if isinstance(obj, Stylesheet):
super(CSSContainer, self).insert(index, obj)
else:
@ -119,7 +119,7 @@ class CSSContainer(list):
# type: (List[Union[unicode, Stylesheet]]) -> None
warnings.warn('builder.css_files is deprecated. '
'Please use app.add_stylesheet() instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
for item in other:
self.append(item)
@ -127,7 +127,7 @@ class CSSContainer(list):
# type: (List[Union[unicode, Stylesheet]]) -> CSSContainer
warnings.warn('builder.css_files is deprecated. '
'Please use app.add_stylesheet() instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
for item in other:
self.append(item)
return self
@ -169,14 +169,14 @@ class JSContainer(list):
# type: (int, unicode) -> None
warnings.warn('builder.script_files is deprecated. '
'Please use app.add_js_file() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
super(JSContainer, self).insert(index, obj)
def extend(self, other): # type: ignore
# type: (List[unicode]) -> None
warnings.warn('builder.script_files is deprecated. '
'Please use app.add_js_file() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
for item in other:
self.append(item)
@ -184,7 +184,7 @@ class JSContainer(list):
# type: (List[unicode]) -> JSContainer
warnings.warn('builder.script_files is deprecated. '
'Please use app.add_js_file() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
for item in other:
self.append(item)
return self
@ -1092,7 +1092,7 @@ class StandaloneHTMLBuilder(Builder):
warnings.warn('Now html_sidebars only allows list of sidebar '
'templates as a value. Support for a string value '
'will be removed at Sphinx-2.0.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
ctx['sidebars'] = sidebars
ctx['customsidebar'] = customsidebar
@ -1161,7 +1161,7 @@ class StandaloneHTMLBuilder(Builder):
"""Simple warn() wrapper for themes."""
warnings.warn('The template function warn() was deprecated. '
'Use warning() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
self.warn(*args, **kwargs)
return '' # return empty string
ctx['warn'] = warn

View File

@ -27,26 +27,26 @@ if False:
def handle_exception(app, args, exception, stderr=sys.stderr):
# type: (Sphinx, Any, Union[Exception, KeyboardInterrupt], IO) -> None
warnings.warn('sphinx.cmdline module is deprecated. Use sphinx.cmd.build instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
build.handle_exception(app, args, exception, stderr)
def jobs_argument(value):
# type: (str) -> int
warnings.warn('sphinx.cmdline module is deprecated. Use sphinx.cmd.build instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return build.jobs_argument(value)
def get_parser():
# type: () -> argparse.ArgumentParser
warnings.warn('sphinx.cmdline module is deprecated. Use sphinx.cmd.build instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return build.get_parser()
def main(argv=sys.argv[1:]): # type: ignore
# type: (List[unicode]) -> int
warnings.warn('sphinx.cmdline module is deprecated. Use sphinx.cmd.build instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return build.main(argv)

View File

@ -168,7 +168,7 @@ class Config(object):
# old style arguments: (dirname, filename, overrides, tags)
warnings.warn('The argument of Config() class has been changed. '
'Use Config.read() to read configuration from conf.py.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
dirname, filename, overrides, tags = args
if dirname is None:
config = {} # type: Dict[unicode, Any]
@ -206,13 +206,13 @@ class Config(object):
def check_types(self):
# type: () -> None
warnings.warn('Config.check_types() is deprecated. Use check_confval_types() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
check_confval_types(None, self)
def check_unicode(self):
# type: () -> None
warnings.warn('Config.check_unicode() is deprecated. Use check_unicode() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
check_unicode(self)
def convert_overrides(self, name, value):

View File

@ -43,25 +43,25 @@ class DeprecatedDict(dict):
def __setitem__(self, key, value):
# type: (unicode, Any) -> None
warnings.warn(self.message, self.warning)
warnings.warn(self.message, self.warning, stacklevel=2)
super(DeprecatedDict, self).__setitem__(key, value)
def setdefault(self, key, default=None):
# type: (unicode, Any) -> None
warnings.warn(self.message, self.warning)
warnings.warn(self.message, self.warning, stacklevel=2)
return super(DeprecatedDict, self).setdefault(key, default)
def __getitem__(self, key):
# type: (unicode) -> None
warnings.warn(self.message, self.warning)
warnings.warn(self.message, self.warning, stacklevel=2)
return super(DeprecatedDict, self).__getitem__(key)
def get(self, key, default=None):
# type: (unicode, Any) -> None
warnings.warn(self.message, self.warning)
warnings.warn(self.message, self.warning, stacklevel=2)
return super(DeprecatedDict, self).get(key, default)
def update(self, other=None): # type: ignore
# type: (Dict) -> None
warnings.warn(self.message, self.warning)
warnings.warn(self.message, self.warning, stacklevel=2)
super(DeprecatedDict, self).update(other)

View File

@ -62,7 +62,7 @@ class HighlightLang(Highlight):
# type: () -> List[nodes.Node]
warnings.warn('highlightlang directive is deprecated. '
'Please use highlight directive instead.',
RemovedInSphinx40Warning)
RemovedInSphinx40Warning, stacklevel=2)
return Highlight.run(self)

View File

@ -953,7 +953,7 @@ class StandardDomain(Domain):
"""
warnings.warn('StandardDomain.get_figtype() is deprecated. '
'Please use get_enumerable_node_type() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return self.get_enumerable_node_type(node)
def get_fignumber(self, env, builder, figtype, docname, target_node):

View File

@ -276,7 +276,7 @@ class BuildEnvironment(object):
def set_warnfunc(self, func):
# type: (Callable) -> None
warnings.warn('env.set_warnfunc() is now deprecated. Use sphinx.util.logging instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
def set_versioning_method(self, method, compare):
# type: (unicode, bool) -> None
@ -572,7 +572,7 @@ class BuildEnvironment(object):
"""
warnings.warn('env.note_toctree() is deprecated. '
'Use sphinx.environment.adapters.toctree.TocTree instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
TocTree(self).note(docname, toctreenode)
def get_toc_for(self, docname, builder):
@ -580,7 +580,7 @@ class BuildEnvironment(object):
"""Return a TOC nodetree -- for use on the same page only!"""
warnings.warn('env.get_toc_for() is deprecated. '
'Use sphinx.environment.adapters.toctre.TocTree instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
return TocTree(self).get_toc_for(docname, builder)
def get_toctree_for(self, docname, builder, collapse, **kwds):
@ -588,7 +588,7 @@ class BuildEnvironment(object):
"""Return the global TOC nodetree."""
warnings.warn('env.get_toctree_for() is deprecated. '
'Use sphinx.environment.adapters.toctre.TocTree instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
return TocTree(self).get_toctree_for(docname, builder, collapse, **kwds)
def get_domain(self, domainname):
@ -683,7 +683,7 @@ class BuildEnvironment(object):
# type: (Builder, bool, Pattern) -> List[Tuple[unicode, List[Tuple[unicode, List[unicode]]]]] # NOQA
warnings.warn('env.create_index() is deprecated. '
'Use sphinx.environment.adapters.indexentreis.IndexEntries instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
return IndexEntries(self).create_index(builder,
group_entries=group_entries,
_fixre=_fixre)
@ -749,32 +749,32 @@ class BuildEnvironment(object):
def update(self, config, srcdir, doctreedir):
# type: (Config, unicode, unicode) -> List[unicode]
warnings.warn('env.update() is deprecated. Please use builder.read() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return self.app.builder.read()
def _read_serial(self, docnames, app):
# type: (List[unicode], Sphinx) -> None
warnings.warn('env._read_serial() is deprecated. Please use builder.read() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return self.app.builder._read_serial(docnames)
def _read_parallel(self, docnames, app, nproc):
# type: (List[unicode], Sphinx, int) -> None
warnings.warn('env._read_parallel() is deprecated. Please use builder.read() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return self.app.builder._read_parallel(docnames, nproc)
def read_doc(self, docname, app=None):
# type: (unicode, Sphinx) -> None
warnings.warn('env.read_doc() is deprecated. Please use builder.read_doc() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
self.app.builder.read_doc(docname)
def write_doctree(self, docname, doctree):
# type: (unicode, nodes.Node) -> None
warnings.warn('env.write_doctree() is deprecated. '
'Please use builder.write_doctree() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
self.app.builder.write_doctree(docname, doctree)
@property
@ -782,7 +782,7 @@ class BuildEnvironment(object):
# type: () -> List[unicode]
warnings.warn('env._nitpick_ignore is deprecated. '
'Please use config.nitpick_ignore instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return self.config.nitpick_ignore
@staticmethod
@ -790,7 +790,7 @@ class BuildEnvironment(object):
# type: (IO, Sphinx) -> BuildEnvironment
warnings.warn('BuildEnvironment.load() is deprecated. '
'Please use pickle.load() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
try:
env = pickle.load(f)
except Exception as exc:
@ -807,7 +807,7 @@ class BuildEnvironment(object):
# type: (unicode, Sphinx) -> BuildEnvironment
warnings.warn('BuildEnvironment.loads() is deprecated. '
'Please use pickle.loads() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
io = BytesIO(string)
return cls.load(io, app)
@ -816,7 +816,7 @@ class BuildEnvironment(object):
# type: (unicode, Sphinx) -> BuildEnvironment
warnings.warn('BuildEnvironment.frompickle() is deprecated. '
'Please use pickle.load() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
with open(filename, 'rb') as f:
return cls.load(f, app)
@ -825,7 +825,7 @@ class BuildEnvironment(object):
# type: (BuildEnvironment, IO) -> None
warnings.warn('BuildEnvironment.dump() is deprecated. '
'Please use pickle.dump() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
pickle.dump(env, f, pickle.HIGHEST_PROTOCOL)
@classmethod
@ -833,7 +833,7 @@ class BuildEnvironment(object):
# type: (BuildEnvironment) -> unicode
warnings.warn('BuildEnvironment.dumps() is deprecated. '
'Please use pickle.dumps() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
io = BytesIO()
cls.dump(env, io)
return io.getvalue()
@ -842,7 +842,7 @@ class BuildEnvironment(object):
# type: (unicode) -> None
warnings.warn('env.topickle() is deprecated. '
'Please use pickle.dump() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
with open(filename, 'wb') as f:
self.dump(self, f)
@ -851,14 +851,14 @@ class BuildEnvironment(object):
# type: () -> Dict[unicode, List[Tuple[unicode, unicode, int, unicode, unicode, unicode]]] # NOQA
warnings.warn('env.versionchanges() is deprecated. '
'Please use ChangeSetDomain instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return self.domaindata['changeset']['changes']
def note_versionchange(self, type, version, node, lineno):
# type: (unicode, unicode, nodes.Node, int) -> None
warnings.warn('env.note_versionchange() is deprecated. '
'Please use ChangeSetDomain.note_changeset() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
node['type'] = type
node['version'] = version
node.line = lineno

View File

@ -133,7 +133,7 @@ class AutodocReporter(object):
# type: (ViewList, Reporter) -> None
warnings.warn('AutodocReporter is now deprecated. '
'Use sphinx.util.docutils.switch_source_input() instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
self.viewlist = viewlist
self.reporter = reporter
@ -1483,17 +1483,17 @@ class DeprecatedDict(dict):
def __setitem__(self, key, value):
# type: (unicode, Any) -> None
warnings.warn(self.message, RemovedInSphinx20Warning)
warnings.warn(self.message, RemovedInSphinx20Warning, stacklevel=2)
super(DeprecatedDict, self).__setitem__(key, value)
def setdefault(self, key, default=None):
# type: (unicode, Any) -> None
warnings.warn(self.message, RemovedInSphinx20Warning)
warnings.warn(self.message, RemovedInSphinx20Warning, stacklevel=2)
super(DeprecatedDict, self).setdefault(key, default)
def update(self, other=None): # type: ignore
# type: (Dict) -> None
warnings.warn(self.message, RemovedInSphinx20Warning)
warnings.warn(self.message, RemovedInSphinx20Warning, stacklevel=2)
super(DeprecatedDict, self).update(other)
@ -1527,7 +1527,7 @@ def add_documenter(cls):
"""Register a new Documenter."""
warnings.warn('sphinx.ext.autodoc.add_documenter() has been deprecated. '
'Please use app.add_autodocumenter() instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
if not issubclass(cls, Documenter):
raise ExtensionError('autodoc documenter %r must be a subclass '
@ -1574,7 +1574,7 @@ def merge_autodoc_default_flags(app, config):
# logger.warning() on 3.0.0 release.
warnings.warn('autodoc_default_flags is now deprecated. '
'Please use autodoc_default_options instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
for option in config.autodoc_default_flags:
if isinstance(option, string_types):

View File

@ -33,7 +33,7 @@ def format_annotation(annotation):
"""
warnings.warn('format_annotation() is now deprecated. '
'Please use sphinx.util.inspect.Signature instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
if isinstance(annotation, typing.TypeVar): # type: ignore
return annotation.__name__
if annotation == Ellipsis:
@ -114,7 +114,7 @@ def formatargspec(function, args, varargs=None, varkw=None, defaults=None,
"""
warnings.warn('formatargspec() is now deprecated. '
'Please use sphinx.util.inspect.Signature instead.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
def format_arg_with_annotation(name):
# type: (str) -> str

View File

@ -195,7 +195,7 @@ def get_documenter(*args):
obj, parent = args
warnings.warn('the interface of get_documenter() has been changed. '
'Please give application object as first argument.',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
if inspect.ismodule(obj):
# ModuleDocumenter.can_document_member always returns False

View File

@ -385,7 +385,7 @@ def debug(argv):
"""Debug functionality to print out an inventory"""
warnings.warn('sphinx.ext.intersphinx.debug() is deprecated. '
'Please use inspect_main() instead',
RemovedInSphinx20Warning)
RemovedInSphinx20Warning, stacklevel=2)
inspect_main(argv[1:])

View File

@ -32,14 +32,14 @@ class MathDirective(MathDirectiveBase):
def run(self):
warnings.warn('sphinx.ext.mathbase.MathDirective is moved to '
'sphinx.directives.patches package.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return super(MathDirective, self).run()
def math_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
warnings.warn('sphinx.ext.mathbase.math_role() is deprecated. '
'Please use docutils.parsers.rst.roles.math_role() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return math_role_base(role, rawtext, text, lineno, inliner, options, content)
@ -47,7 +47,7 @@ def get_node_equation_number(writer, node):
# type: (Writer, nodes.Node) -> unicode
warnings.warn('sphinx.ext.mathbase.get_node_equation_number() is moved to '
'sphinx.util.math package.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
from sphinx.util.math import get_node_equation_number
return get_node_equation_number(writer, node)
@ -56,7 +56,7 @@ def wrap_displaymath(text, label, numbering):
# type: (unicode, unicode, bool) -> unicode
warnings.warn('sphinx.ext.mathbase.wrap_displaymath() is moved to '
'sphinx.util.math package.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
from sphinx.util.math import wrap_displaymath
return wrap_displaymath(text, label, numbering)
@ -67,7 +67,7 @@ def is_in_section_title(node):
from sphinx.util.nodes import traverse_parent
warnings.warn('is_in_section_title() is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
for ancestor in traverse_parent(node):
if isinstance(ancestor, nodes.title) and \
@ -80,6 +80,6 @@ def setup_math(app, htmlinlinevisitors, htmldisplayvisitors):
# type: (Sphinx, Tuple[Callable, Callable], Tuple[Callable, Callable]) -> None
warnings.warn('setup_math() is deprecated. '
'Please use app.add_html_math_renderer() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
app.add_html_math_renderer('unknown', htmlinlinevisitors, htmldisplayvisitors)

View File

@ -252,7 +252,7 @@ def migrate_viewcode_import(app, config):
if config.viewcode_import is not None:
warnings.warn('viewcode_import was renamed to viewcode_follow_imported_members. '
'Please update your configuration.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
def setup(app):

View File

@ -91,7 +91,7 @@ class PygmentsBridge(object):
self.trim_doctest_flags = trim_doctest_flags
if trim_doctest_flags is not None:
warnings.warn('trim_doctest_flags option for PygmentsBridge is now deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
def get_formatter(self, **kwargs):
# type: (Any) -> Formatter
@ -101,7 +101,7 @@ class PygmentsBridge(object):
def unhighlighted(self, source):
# type: (unicode) -> unicode
warnings.warn('PygmentsBridge.unhighlighted() is now deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
if self.dest == 'html':
return '<pre>' + htmlescape(source) + '</pre>\n'
else:

View File

@ -129,13 +129,13 @@ class SphinxI18nReader(SphinxBaseReader):
# type: (int) -> None
"""Stores the source line number of original text."""
warnings.warn('SphinxI18nReader.set_lineno_for_reporter() is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
@property
def line(self):
# type: () -> int
warnings.warn('SphinxI18nReader.line is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return 0

View File

@ -187,7 +187,7 @@ def mygettext(string):
not bound yet at that time.
"""
warnings.warn('sphinx.locale.mygettext() is deprecated. Please use `_()` instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return _(string)
@ -197,7 +197,7 @@ def lazy_gettext(string):
# if isinstance(string, _TranslationProxy):
# return string
warnings.warn('sphinx.locale.laxy_gettext() is deprecated. Please use `_()` instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return _TranslationProxy(mygettext, string) # type: ignore
@ -332,7 +332,7 @@ __ = get_translation('sphinx', 'console')
def l_(*args):
warnings.warn('sphinx.locale.l_() is deprecated. Please use `_()` instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return _(*args)

View File

@ -28,12 +28,12 @@ class Make(make_mode.Make):
def __init__(self, *args):
warnings.warn('sphinx.make_mode.Make is deprecated. '
'Please use sphinx.cmd.make_mode.Make instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
super(Make, self).__init__(*args)
def run_make_mode(args):
warnings.warn('sphinx.make_mode.run_make_mode() is deprecated. '
'Please use sphinx.cmd.make_mode.run_make_mode() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return make_mode.run_make_mode(args)

View File

@ -186,7 +186,7 @@ class SphinxComponentRegistry(object):
# type: (Type[Domain]) -> None
warnings.warn('registry.override_domain() is deprecated. '
'Use app.add_domain(domain, override=True) instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
self.add_domain(domain, override=True)
def add_directive_to_domain(self, domain, name, obj, has_content=None, argument_spec=None,
@ -291,7 +291,7 @@ class SphinxComponentRegistry(object):
# old style arguments: (suffix, source_parser)
warnings.warn('app.add_source_parser() does not support suffix argument. '
'Use app.add_source_suffix() instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=3)
suffix = args[0]
parser = args[1]
@ -301,7 +301,7 @@ class SphinxComponentRegistry(object):
if len(parser.supported) == 0:
warnings.warn('Old source_parser has been detected. Please fill Parser.supported '
'attribute: %s' % parser.__name__,
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=3)
# create a map from filetype to parser
for filetype in parser.supported:

View File

@ -563,7 +563,7 @@ class SearchJapanese(SearchLanguage):
dotted_path = self.splitters[type]
warnings.warn('html_search_options["type"]: %s is deprecated. '
'Please give "%s" instead.' % (type, dotted_path),
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
else:
dotted_path = type
try:

View File

@ -207,7 +207,7 @@ def copy_static_entry(source, targetdir, builder, context={},
Handles all possible cases of files, directories and subdirectories.
"""
warnings.warn('sphinx.util.copy_static_entry is deprecated for removal',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
if exclude_matchers:
relpath = relative_path(path.join(builder.srcdir, 'dummy'), source)

View File

@ -124,7 +124,7 @@ def find_catalog_source_files(locale_dirs, locale, domains=None, gettext_compact
"""
if gettext_compact is not None:
warnings.warn('gettext_compact argument for find_catalog_source_files() '
'is deprecated.', RemovedInSphinx30Warning)
'is deprecated.', RemovedInSphinx30Warning, stacklevel=2)
catalogs = set() # type: Set[CatalogInfo]

View File

@ -87,7 +87,7 @@ def guess_mimetype(filename='', content=None, default=None):
return mime_suffixes[ext]
elif content:
warnings.warn('The content argument of guess_mimetype() is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return guess_mimetype_for_stream(BytesIO(content), default=default)
elif path.exists(filename):
with open(filename, 'rb') as f:

View File

@ -186,7 +186,7 @@ def ustrftime(format, *args):
# type: (unicode, Any) -> unicode
"""[DEPRECATED] strftime for unicode strings."""
warnings.warn('sphinx.util.osutil.ustrtime is deprecated for removal',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
if not args:
# If time is not specified, try to use $SOURCE_DATE_EPOCH variable

View File

@ -186,6 +186,6 @@ def prepare(document):
# type: (nodes.Node) -> None
"""Simple wrapper for UIDTransform."""
warnings.warn('versioning.prepare() is deprecated. Use UIDTransform instead.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
transform = UIDTransform(document)
transform.apply()

View File

@ -902,7 +902,7 @@ class HTMLTranslator(BaseTranslator):
def highlightlang(self):
# type: () -> unicode
warnings.warn('HTMLTranslator.highlightlang is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return self.builder.config.highlight_language
@property
@ -916,12 +916,12 @@ class HTMLTranslator(BaseTranslator):
def highlightopts(self):
# type: () -> unicode
warnings.warn('HTMLTranslator.highlightopts is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return self.builder.config.highlight_options
@property
def highlightlinenothreshold(self):
# type: () -> int
warnings.warn('HTMLTranslator.highlightlinenothreshold is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return sys.maxsize

View File

@ -853,26 +853,26 @@ class HTML5Translator(BaseTranslator):
def highlightlang(self):
# type: () -> unicode
warnings.warn('HTMLTranslator.highlightlang is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return self.builder.config.highlight_language
@property
def highlightlang_base(self):
# type: () -> unicode
warnings.warn('HTMLTranslator.highlightlang_base is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return self.builder.config.highlight_language
@property
def highlightopts(self):
# type: () -> unicode
warnings.warn('HTMLTranslator.highlightopts is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return self.builder.config.highlight_options
@property
def highlightlinenothreshold(self):
# type: () -> int
warnings.warn('HTMLTranslator.highlightlinenothreshold is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return sys.maxsize

View File

@ -218,7 +218,7 @@ class ExtBabel(Babel):
def get_shorthandoff(self):
# type: () -> unicode
warnings.warn('ExtBabel.get_shorthandoff() is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return SHORTHANDOFF
def uses_cyrillic(self):
@ -289,14 +289,14 @@ class Table(object):
def caption_footnotetexts(self):
# type: () -> List[unicode]
warnings.warn('table.caption_footnotetexts is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return []
@property
def header_footnotetexts(self):
# type: () -> List[unicode]
warnings.warn('table.header_footnotetexts is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return []
def is_longtable(self):
@ -697,7 +697,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
def restrict_footnote(self, node):
# type: (nodes.Node) -> None
warnings.warn('LaTeXWriter.restrict_footnote() is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
if self.footnote_restricted is False:
self.footnote_restricted = node
@ -706,7 +706,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
def unrestrict_footnote(self, node):
# type: (nodes.Node) -> None
warnings.warn('LaTeXWriter.unrestrict_footnote() is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
if self.footnote_restricted == node:
self.footnote_restricted = False
@ -2545,60 +2545,60 @@ class LaTeXTranslator(nodes.NodeVisitor):
def footnotestack(self):
# type: () -> List[Dict[unicode, List[Union[collected_footnote, bool]]]]
warnings.warn('LaTeXWriter.footnotestack is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return []
@property
def bibitems(self):
# type: () -> List[List[unicode]]
warnings.warn('LaTeXTranslator.bibitems() is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return []
@property
def in_container_literal_block(self):
# type: () -> int
warnings.warn('LaTeXTranslator.in_container_literal_block is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return 0
@property
def next_section_ids(self):
# type: () -> Set[unicode]
warnings.warn('LaTeXTranslator.next_section_ids is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return set()
@property
def next_hyperlink_ids(self):
# type: () -> Dict
warnings.warn('LaTeXTranslator.next_hyperlink_ids is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return {}
def push_hyperlink_ids(self, figtype, ids):
# type: (unicode, Set[unicode]) -> None
warnings.warn('LaTeXTranslator.push_hyperlink_ids() is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
pass
def pop_hyperlink_ids(self, figtype):
# type: (unicode) -> Set[unicode]
warnings.warn('LaTeXTranslator.pop_hyperlink_ids() is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return set()
@property
def hlsettingstack(self):
# type: () -> List[List[Union[unicode, int]]]
warnings.warn('LaTeXTranslator.hlsettingstack is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
return [[self.builder.config.highlight_language, sys.maxsize]]
def check_latex_elements(self):
# type: () -> None
warnings.warn('check_latex_elements() is deprecated.',
RemovedInSphinx30Warning)
RemovedInSphinx30Warning, stacklevel=2)
for key in self.builder.config.latex_elements:
if key not in self.elements: