diff --git a/CHANGES b/CHANGES index b103c19fab3..7c3155e3664 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,8 @@ Deprecated Features added -------------- +* #5471: Show appropriate deprecation warnings + Bugs fixed ---------- diff --git a/sphinx/__init__.py b/sphinx/__init__.py index 9b140572888..880992605f4 100644 --- a/sphinx/__init__.py +++ b/sphinx/__init__.py @@ -31,8 +31,7 @@ # 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') diff --git a/sphinx/addnodes.py b/sphinx/addnodes.py index 331fe52256d..8ced71d0913 100644 --- a/sphinx/addnodes.py +++ b/sphinx/addnodes.py @@ -205,7 +205,7 @@ def __getitem__(self, key): 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 @@ def __getitem__(self, key): 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) diff --git a/sphinx/application.py b/sphinx/application.py index 64433915a1a..1f8ec58df73 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -385,7 +385,7 @@ def warn(self, message, location=None, type=None, subtype=None): 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 @@ def info(self, message='', nonl=False): 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 @@ def verbose(self, message, *args, **kwargs): 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 @@ def debug(self, message, *args, **kwargs): 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 @@ def debug2(self, message, *args, **kwargs): 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 @@ def import_object(self, objname, source=None): """ 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 @@ def enumerable_nodes(self): # 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 @@ def override_domain(self, domain): """ 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 @@ def add_description_unit(self, directivename, rolename, indextemplate='', """ 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 @@ def add_javascript(self, filename, **kwargs): """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 @@ def add_stylesheet(self, filename, alternate=False, title=None): """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: diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index 9c75376312f..cfd005b1030 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -150,7 +150,7 @@ def translator_class(self): 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 diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index e8558d054cb..d4c9a3a10a0 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -109,7 +109,7 @@ def insert(self, index, obj): # 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 @@ def extend(self, other): # type: ignore # 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 @@ def __iadd__(self, other): # type: ignore # 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 @@ def insert(self, index, obj): # 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 @@ def __iadd__(self, other): # type: ignore # 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 @@ def has_wildcard(pattern): 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 @@ def warn(*args, **kwargs): """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 diff --git a/sphinx/cmdline.py b/sphinx/cmdline.py index 10835d2e7e6..252f95bbc92 100644 --- a/sphinx/cmdline.py +++ b/sphinx/cmdline.py @@ -27,26 +27,26 @@ 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) diff --git a/sphinx/config.py b/sphinx/config.py index d4e1ab05546..e456d00b640 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -168,7 +168,7 @@ def __init__(self, *args): # 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 @@ def read(cls, confdir, overrides=None, tags=None): 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): diff --git a/sphinx/deprecation.py b/sphinx/deprecation.py index f95e8dbff7c..b3219a0b29f 100644 --- a/sphinx/deprecation.py +++ b/sphinx/deprecation.py @@ -43,25 +43,25 @@ def __init__(self, data, message, warning): 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) diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py index a98ab588367..30ded6dd4ff 100644 --- a/sphinx/directives/code.py +++ b/sphinx/directives/code.py @@ -62,7 +62,7 @@ def run(self): # type: () -> List[nodes.Node] warnings.warn('highlightlang directive is deprecated. ' 'Please use highlight directive instead.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) return Highlight.run(self) diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index 37bac2accd5..7f06acd1e99 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -953,7 +953,7 @@ def get_figtype(self, node): """ 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): diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py index 4a79db3db02..058cbc8e98d 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -276,7 +276,7 @@ def _update_settings(self, config): 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 @@ def note_toctree(self, docname, toctreenode): """ 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 @@ def get_toc_for(self, docname, builder): """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 @@ def get_toctree_for(self, docname, builder, collapse, **kwds): """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 @@ def create_index(self, builder, group_entries=True, # 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 @@ def check_consistency(self): 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 @@ def _nitpick_ignore(self): # 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 @@ def load(f, app=None): # 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 @@ def loads(cls, string, app=None): # 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 @@ def frompickle(cls, filename, app): # 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 @@ def dump(env, f): # 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 @@ def dumps(cls, env): # 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 @@ def topickle(self, filename): # 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 @@ def versionchanges(self): # 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 diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 6823505eece..1b1f7a24b6b 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -133,7 +133,7 @@ def __init__(self, viewlist, reporter): # 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 @@ def __init__(self, message): 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): diff --git a/sphinx/ext/autodoc/inspector.py b/sphinx/ext/autodoc/inspector.py index be42237c656..52a79fed5a3 100644 --- a/sphinx/ext/autodoc/inspector.py +++ b/sphinx/ext/autodoc/inspector.py @@ -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 diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index c450733ab0a..8ffa8fcdc47 100644 --- a/sphinx/ext/autosummary/__init__.py +++ b/sphinx/ext/autosummary/__init__.py @@ -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 diff --git a/sphinx/ext/intersphinx.py b/sphinx/ext/intersphinx.py index e3f8dc275ba..8d6a3e16428 100644 --- a/sphinx/ext/intersphinx.py +++ b/sphinx/ext/intersphinx.py @@ -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:]) diff --git a/sphinx/ext/mathbase.py b/sphinx/ext/mathbase.py index 421ea6a0379..076edaf3718 100644 --- a/sphinx/ext/mathbase.py +++ b/sphinx/ext/mathbase.py @@ -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) diff --git a/sphinx/ext/viewcode.py b/sphinx/ext/viewcode.py index ca944a6363a..425482c3a29 100644 --- a/sphinx/ext/viewcode.py +++ b/sphinx/ext/viewcode.py @@ -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): diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py index 21e3420ba13..f52e9901918 100644 --- a/sphinx/highlighting.py +++ b/sphinx/highlighting.py @@ -91,7 +91,7 @@ def __init__(self, dest='html', stylename='sphinx', trim_doctest_flags=None): 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 @@ def get_formatter(self, **kwargs): def unhighlighted(self, source): # type: (unicode) -> unicode warnings.warn('PygmentsBridge.unhighlighted() is now deprecated.', - RemovedInSphinx30Warning) + RemovedInSphinx30Warning, stacklevel=2) if self.dest == 'html': return '
' + htmlescape(source) + '
\n' else: diff --git a/sphinx/io.py b/sphinx/io.py index ad76c2afba6..4da4e95a933 100644 --- a/sphinx/io.py +++ b/sphinx/io.py @@ -129,13 +129,13 @@ def set_lineno_for_reporter(self, lineno): # 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 diff --git a/sphinx/locale/__init__.py b/sphinx/locale/__init__.py index 7f69d1dca8c..acad829c82f 100644 --- a/sphinx/locale/__init__.py +++ b/sphinx/locale/__init__.py @@ -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 @@ def gettext(message, *args): def l_(*args): warnings.warn('sphinx.locale.l_() is deprecated. Please use `_()` instead.', - RemovedInSphinx30Warning) + RemovedInSphinx30Warning, stacklevel=2) return _(*args) diff --git a/sphinx/make_mode.py b/sphinx/make_mode.py index 4510fc0ebd9..ffc609a031e 100644 --- a/sphinx/make_mode.py +++ b/sphinx/make_mode.py @@ -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) diff --git a/sphinx/registry.py b/sphinx/registry.py index fc9dce31639..4fd808f04f8 100644 --- a/sphinx/registry.py +++ b/sphinx/registry.py @@ -186,7 +186,7 @@ def override_domain(self, domain): # 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 @@ def add_source_parser(self, *args, **kwargs): # 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 @@ def add_source_parser(self, *args, **kwargs): 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: diff --git a/sphinx/search/ja.py b/sphinx/search/ja.py index a48a0df69c3..e1fcaa920b3 100644 --- a/sphinx/search/ja.py +++ b/sphinx/search/ja.py @@ -563,7 +563,7 @@ def init(self, options): 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: diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index a9d112a9f74..109b098ceee 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -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) diff --git a/sphinx/util/i18n.py b/sphinx/util/i18n.py index edaebebdae5..e7c8cc9f266 100644 --- a/sphinx/util/i18n.py +++ b/sphinx/util/i18n.py @@ -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] diff --git a/sphinx/util/images.py b/sphinx/util/images.py index d5e0db2d72d..c71da38b951 100644 --- a/sphinx/util/images.py +++ b/sphinx/util/images.py @@ -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: diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index 4c75009eef1..d1c15621cbd 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -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 diff --git a/sphinx/versioning.py b/sphinx/versioning.py index 58b648069d7..78383464c3b 100644 --- a/sphinx/versioning.py +++ b/sphinx/versioning.py @@ -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() diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py index e2899e8a4ee..66f3bf8f4bc 100644 --- a/sphinx/writers/html.py +++ b/sphinx/writers/html.py @@ -902,7 +902,7 @@ def unknown_visit(self, node): 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 @@ def highlightlang_base(self): 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 diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py index c14775b9c5b..41c665cddff 100644 --- a/sphinx/writers/html5.py +++ b/sphinx/writers/html5.py @@ -853,26 +853,26 @@ def unknown_visit(self, node): 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 diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 4ef8ddbcacf..7febdef7d08 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -218,7 +218,7 @@ def __init__(self, language_code, use_polyglossia=False): 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 @@ def __init__(self, node): 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 @@ def popbody(self): 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 @@ def restrict_footnote(self, node): 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 @@ def unknown_visit(self, node): 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: