diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-05-03 22:40:19 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-05-03 23:34:35 +0900 |
commit | 41b4a77dea51cf5eb16f9a3fdc27426827313d54 (patch) | |
tree | aad1d45e1e780ef69a4872d1d4122d5292fc0755 | |
parent | a5cba8cdbb9f44721885c8555bf875df1f59e199 (diff) | |
download | sphinx-git-41b4a77dea51cf5eb16f9a3fdc27426827313d54.tar.gz |
Add stacklevel parameter to warnings.warn() call
31 files changed, 71 insertions, 67 deletions
diff --git a/sphinx/application.py b/sphinx/application.py index d2fd776ff..4014a2efa 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -990,7 +990,7 @@ class Sphinx: if isinstance(lexer, Lexer): warnings.warn('app.add_lexer() API changed; ' 'Please give lexer class instead instance', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) lexers[alias] = lexer else: lexer_classes[alias] = lexer diff --git a/sphinx/builders/_epub_base.py b/sphinx/builders/_epub_base.py index b2d8413a8..f26a1ba9f 100644 --- a/sphinx/builders/_epub_base.py +++ b/sphinx/builders/_epub_base.py @@ -173,7 +173,7 @@ class EpubBuilder(StandaloneHTMLBuilder): """Replace all characters not allowed in text an attribute values.""" warnings.warn( '%s.esc() is deprecated. Use html.escape() instead.' % self.__class__.__name__, - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) name = name.replace('&', '&') name = name.replace('<', '<') name = name.replace('>', '>') diff --git a/sphinx/builders/applehelp.py b/sphinx/builders/applehelp.py index f081f9fe5..759ba66da 100644 --- a/sphinx/builders/applehelp.py +++ b/sphinx/builders/applehelp.py @@ -32,7 +32,7 @@ deprecated_alias('sphinx.builders.applehelp', def setup(app: Sphinx) -> Dict[str, Any]: warnings.warn('sphinx.builders.applehelp has been moved to sphinxcontrib-applehelp.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) app.setup_extension('sphinxcontrib.applehelp') return { diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py index 320c7feb6..85767b14e 100644 --- a/sphinx/builders/html/__init__.py +++ b/sphinx/builders/html/__init__.py @@ -882,7 +882,7 @@ class StandaloneHTMLBuilder(Builder): 'The %s.feed() method signature is deprecated. Update to ' '%s.feed(docname, filename, title, doctree).' % ( indexer_name, indexer_name), - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) def _get_local_toctree(self, docname: str, collapse: bool = True, **kwargs: Any) -> str: if 'includehidden' not in kwargs: diff --git a/sphinx/builders/htmlhelp.py b/sphinx/builders/htmlhelp.py index 8732de7fd..1d6304d38 100644 --- a/sphinx/builders/htmlhelp.py +++ b/sphinx/builders/htmlhelp.py @@ -32,7 +32,7 @@ deprecated_alias('sphinx.builders.htmlhelp', def setup(app: Sphinx) -> Dict[str, Any]: warnings.warn('sphinx.builders.htmlhelp has been moved to sphinxcontrib-htmlhelp.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) app.setup_extension('sphinxcontrib.htmlhelp') return { diff --git a/sphinx/builders/latex/__init__.py b/sphinx/builders/latex/__init__.py index b1fe4b73e..225975c20 100644 --- a/sphinx/builders/latex/__init__.py +++ b/sphinx/builders/latex/__init__.py @@ -363,7 +363,7 @@ class LaTeXBuilder(Builder): def apply_transforms(self, doctree: nodes.document) -> None: warnings.warn('LaTeXBuilder.apply_transforms() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) def finish(self) -> None: self.copy_image_files() diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py index 8f8ae58a1..29d2e8187 100644 --- a/sphinx/cmd/quickstart.py +++ b/sphinx/cmd/quickstart.py @@ -187,7 +187,7 @@ def do_prompt(text: str, default: str = None, validator: Callable[[str], Any] = def convert_python_source(source: str, rex: Pattern = re.compile(r"[uU]('.*?')")) -> str: # remove Unicode literal prefixes warnings.warn('convert_python_source() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) return rex.sub('\\1', source) diff --git a/sphinx/config.py b/sphinx/config.py index 19a8f6c4f..6e6c256c5 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -444,7 +444,7 @@ def check_unicode(config: Config) -> None: since that can result in UnicodeErrors all over the place """ warnings.warn('sphinx.config.check_unicode() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) nonascii_re = re.compile(br'[\x80-\xff]') diff --git a/sphinx/domains/math.py b/sphinx/domains/math.py index 88b6e4eb8..e77bd0ed7 100644 --- a/sphinx/domains/math.py +++ b/sphinx/domains/math.py @@ -142,7 +142,7 @@ class MathDomain(Domain): def add_equation(self, env: BuildEnvironment, docname: str, labelid: str) -> int: warnings.warn('MathDomain.add_equation() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) if labelid in self.equations: path = env.doc2path(self.equations[labelid][0]) msg = __('duplicate label of equation %s, other instance in %s') % (labelid, path) @@ -154,7 +154,7 @@ class MathDomain(Domain): def get_next_equation_number(self, docname: str) -> int: warnings.warn('MathDomain.get_next_equation_number() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) targets = [eq for eq in self.equations.values() if eq[0] == docname] return len(targets) + 1 diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index 99339ccbd..39c7de142 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -530,10 +530,11 @@ class PyModulelevel(PyObject): if cls.__name__ != 'DirectiveAdapter': warnings.warn('PyModulelevel is deprecated. ' 'Please check the implementation of %s' % cls, - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) break else: - warnings.warn('PyModulelevel is deprecated', RemovedInSphinx40Warning) + warnings.warn('PyModulelevel is deprecated', + RemovedInSphinx40Warning, stacklevel=2) return super().run() @@ -675,10 +676,11 @@ class PyClassmember(PyObject): if cls.__name__ != 'DirectiveAdapter': warnings.warn('PyClassmember is deprecated. ' 'Please check the implementation of %s' % cls, - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) break else: - warnings.warn('PyClassmember is deprecated', RemovedInSphinx40Warning) + warnings.warn('PyClassmember is deprecated', + RemovedInSphinx40Warning, stacklevel=2) return super().run() @@ -896,10 +898,11 @@ class PyDecoratorMixin: if cls.__name__ != 'DirectiveAdapter': warnings.warn('PyDecoratorMixin is deprecated. ' 'Please check the implementation of %s' % cls, - RemovedInSphinx50Warning) + RemovedInSphinx50Warning, stacklevel=2) break else: - warnings.warn('PyDecoratorMixin is deprecated', RemovedInSphinx50Warning) + warnings.warn('PyDecoratorMixin is deprecated', + RemovedInSphinx50Warning, stacklevel=2) ret = super().handle_signature(sig, signode) # type: ignore signode.insert(0, addnodes.desc_addname('@', '@')) diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index 74e901779..6dc597022 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -292,7 +292,7 @@ def make_glossary_term(env: "BuildEnvironment", textnodes: Iterable[Node], index document.note_explicit_target(term) else: warnings.warn('make_glossary_term() expects document is passed as an argument.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) gloss_entries = env.temp_data.setdefault('gloss_entries', set()) node_id = nodes.make_id('term-' + termtext) if node_id == 'term': @@ -660,7 +660,7 @@ class StandardDomain(Domain): def add_object(self, objtype: str, name: str, docname: str, labelid: str) -> None: warnings.warn('StandardDomain.add_object() is deprecated.', - RemovedInSphinx50Warning) + RemovedInSphinx50Warning, stacklevel=2) self.objects[objtype, name] = (docname, labelid) @property @@ -786,7 +786,7 @@ class StandardDomain(Domain): resolver = self._resolve_option_xref elif typ == 'citation': warnings.warn('pending_xref(domain=std, type=citation) is deprecated: %r' % node, - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) domain = env.get_domain('citation') return domain.resolve_xref(env, fromdocname, builder, typ, target, node, contnode) elif typ == 'term': @@ -1082,15 +1082,15 @@ class StandardDomain(Domain): def note_citations(self, env: "BuildEnvironment", docname: str, document: nodes.document) -> None: # NOQA warnings.warn('StandardDomain.note_citations() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) def note_citation_refs(self, env: "BuildEnvironment", docname: str, document: nodes.document) -> None: # NOQA warnings.warn('StandardDomain.note_citation_refs() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) def note_labels(self, env: "BuildEnvironment", docname: str, document: nodes.document) -> None: # NOQA warnings.warn('StandardDomain.note_labels() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) def setup(app: "Sphinx") -> Dict[str, Any]: diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py index c8735461d..6584ac6d8 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -331,10 +331,10 @@ class BuildEnvironment: """ if suffix: warnings.warn('The suffix argument for doc2path() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) if base not in (True, False, None): warnings.warn('The string style base argument for doc2path() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) pathname = self.project.doc2path(docname, base is True) if suffix: diff --git a/sphinx/environment/collectors/indexentries.py b/sphinx/environment/collectors/indexentries.py index 2ef59909b..a4c0450d2 100644 --- a/sphinx/environment/collectors/indexentries.py +++ b/sphinx/environment/collectors/indexentries.py @@ -29,7 +29,7 @@ class IndexEntriesCollector(EnvironmentCollector): def __init__(self) -> None: warnings.warn('IndexEntriesCollector is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) def clear_doc(self, app: Sphinx, env: BuildEnvironment, docname: str) -> None: env.indexentries.pop(docname, None) diff --git a/sphinx/ext/apidoc.py b/sphinx/ext/apidoc.py index 23be0a00a..b01604617 100644 --- a/sphinx/ext/apidoc.py +++ b/sphinx/ext/apidoc.py @@ -54,7 +54,7 @@ template_dir = path.join(package_dir, 'templates', 'apidoc') def makename(package: str, module: str) -> str: """Join package and module with a dot.""" warnings.warn('makename() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) # Both package and module can be None/empty. if package: name = package @@ -112,7 +112,7 @@ def write_file(name: str, text: str, opts: Any) -> None: def format_heading(level: int, text: str, escape: bool = True) -> str: """Create a heading of <level> [1, 2 or 3 supported].""" warnings.warn('format_warning() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) if escape: text = rst.escape(text) underlining = ['=', '-', '~', ][level - 1] * len(text) @@ -122,7 +122,7 @@ def format_heading(level: int, text: str, escape: bool = True) -> str: def format_directive(module: str, package: str = None) -> str: """Create the automodule directive and add the options.""" warnings.warn('format_directive() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) directive = '.. automodule:: %s\n' % module_join(package, module) for option in OPTIONS: directive += ' :%s:\n' % option @@ -209,7 +209,7 @@ def create_modules_toc_file(modules: List[str], opts: Any, name: str = 'modules' def shall_skip(module: str, opts: Any, excludes: List[str] = []) -> bool: """Check if we want to skip this module.""" warnings.warn('shall_skip() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) # skip if the file doesn't exist and not using implicit namespaces if not opts.implicit_namespaces and not path.exists(module): return True diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 609928422..36e0b6455 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -434,7 +434,7 @@ class Documenter: if encoding is not None: warnings.warn("The 'encoding' argument to autodoc.%s.get_doc() is deprecated." % self.__class__.__name__, - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) if ignore is not None: warnings.warn("The 'ignore' argument to autodoc.%s.get_doc() is deprecated." % self.__class__.__name__, @@ -953,7 +953,7 @@ class DocstringSignatureMixin: if encoding is not None: warnings.warn("The 'encoding' argument to autodoc.%s._find_signature() is " "deprecated." % self.__class__.__name__, - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) docstrings = self.get_doc() self._new_docstrings = docstrings[:] result = None @@ -987,7 +987,7 @@ class DocstringSignatureMixin: if encoding is not None: warnings.warn("The 'encoding' argument to autodoc.%s.get_doc() is deprecated." % self.__class__.__name__, - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) lines = getattr(self, '_new_docstrings', None) if lines is not None: return lines @@ -1247,7 +1247,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type: if encoding is not None: warnings.warn("The 'encoding' argument to autodoc.%s.get_doc() is deprecated." % self.__class__.__name__, - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) lines = getattr(self, '_new_docstrings', None) if lines is not None: return lines @@ -1757,7 +1757,7 @@ class SlotsAttributeDocumenter(AttributeDocumenter): def get_documenters(app: Sphinx) -> Dict[str, "Type[Documenter]"]: """Returns registered Documenter classes""" - warnings.warn("get_documenters() is deprecated.", RemovedInSphinx50Warning) + warnings.warn("get_documenters() is deprecated.", RemovedInSphinx50Warning, stacklevel=2) return app.registry.documenters diff --git a/sphinx/ext/autodoc/directive.py b/sphinx/ext/autodoc/directive.py index 3be19f089..9a3428f5d 100644 --- a/sphinx/ext/autodoc/directive.py +++ b/sphinx/ext/autodoc/directive.py @@ -66,7 +66,7 @@ class DocumenterBridge: else: # create fake object for self.state.document.settings.tab_width warnings.warn('DocumenterBridge requires a state object on instantiation.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) settings = Struct(tab_width=8) document = Struct(settings=settings) self.state = Struct(document=document) diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index 57f775272..ed49c56df 100644 --- a/sphinx/ext/autosummary/__init__.py +++ b/sphinx/ext/autosummary/__init__.py @@ -659,7 +659,7 @@ def autolink_role(typ: str, rawtext: str, etext: str, lineno: int, inliner: Inli Expands to ':obj:`text`' if `text` is an object that can be imported; otherwise expands to '*text*'. """ - warnings.warn('autolink_role() is deprecated.', RemovedInSphinx40Warning) + warnings.warn('autolink_role() is deprecated.', RemovedInSphinx40Warning, stacklevel=2) env = inliner.document.settings.env pyobj_role = env.get_domain('py').role('obj') objects, msg = pyobj_role('obj', rawtext, etext, lineno, inliner, options, content) diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py index 693f0e5b0..e5bdc0e30 100644 --- a/sphinx/ext/autosummary/generate.py +++ b/sphinx/ext/autosummary/generate.py @@ -126,7 +126,7 @@ class AutosummaryRenderer: RemovedInSphinx50Warning, stacklevel=2) if template_dir: warnings.warn('template_dir argument for AutosummaryRenderer is deprecated.', - RemovedInSphinx50Warning) + RemovedInSphinx50Warning, stacklevel=2) system_templates_path = [os.path.join(package_dir, 'ext', 'autosummary', 'templates')] loader = SphinxTemplateLoader(app.srcdir, app.config.templates_path, @@ -279,25 +279,25 @@ def generate_autosummary_docs(sources: List[str], output_dir: str = None, overwrite: bool = True) -> None: if info: warnings.warn('info argument for generate_autosummary_docs() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) _info = info else: _info = logger.info if warn: warnings.warn('warn argument for generate_autosummary_docs() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) _warn = warn else: _warn = logger.warning if builder: warnings.warn('builder argument for generate_autosummary_docs() is deprecated.', - RemovedInSphinx50Warning) + RemovedInSphinx50Warning, stacklevel=2) if template_dir: warnings.warn('template_dir argument for generate_autosummary_docs() is deprecated.', - RemovedInSphinx50Warning) + RemovedInSphinx50Warning, stacklevel=2) showed_sources = list(sorted(sources)) if len(showed_sources) > 20: @@ -390,7 +390,7 @@ def find_autosummary_in_docstring(name: str, module: str = None, filename: str = """ if module: warnings.warn('module argument for find_autosummary_in_docstring() is deprecated.', - RemovedInSphinx50Warning) + RemovedInSphinx50Warning, stacklevel=2) try: real_name, obj, parent, modname = import_by_name(name) diff --git a/sphinx/ext/doctest.py b/sphinx/ext/doctest.py index 645521f9b..26966016d 100644 --- a/sphinx/ext/doctest.py +++ b/sphinx/ext/doctest.py @@ -47,7 +47,7 @@ doctestopt_re = re.compile(r'#\s*doctest:.+$', re.MULTILINE) def doctest_encode(text: str, encoding: str) -> str: warnings.warn('doctest_encode() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) return text diff --git a/sphinx/ext/todo.py b/sphinx/ext/todo.py index c5cacc437..bfb46903f 100644 --- a/sphinx/ext/todo.py +++ b/sphinx/ext/todo.py @@ -105,7 +105,7 @@ class TodoDomain(Domain): def process_todos(app: Sphinx, doctree: nodes.document) -> None: - warnings.warn('process_todos() is deprecated.', RemovedInSphinx40Warning) + warnings.warn('process_todos() is deprecated.', RemovedInSphinx40Warning, stacklevel=2) # collect all todos in the environment # this is not done in the directive itself because it some transformations # must have already been run, e.g. substitutions @@ -221,7 +221,8 @@ def process_todo_nodes(app: Sphinx, doctree: nodes.document, fromdocname: str) - """Replace all todolist nodes with a list of the collected todos. Augment each todo with a backlink to the original location. """ - warnings.warn('process_todo_nodes() is deprecated.', RemovedInSphinx40Warning) + warnings.warn('process_todo_nodes() is deprecated.', + RemovedInSphinx40Warning, stacklevel=2) domain = cast(TodoDomain, app.env.get_domain('todo')) todos = sum(domain.todos.values(), []) # type: List[todo_node] @@ -273,7 +274,7 @@ def process_todo_nodes(app: Sphinx, doctree: nodes.document, fromdocname: str) - def purge_todos(app: Sphinx, env: BuildEnvironment, docname: str) -> None: - warnings.warn('purge_todos() is deprecated.', RemovedInSphinx40Warning) + warnings.warn('purge_todos() is deprecated.', RemovedInSphinx40Warning, stacklevel=2) if not hasattr(env, 'todo_all_todos'): return env.todo_all_todos = [todo for todo in env.todo_all_todos # type: ignore @@ -282,7 +283,7 @@ def purge_todos(app: Sphinx, env: BuildEnvironment, docname: str) -> None: def merge_info(app: Sphinx, env: BuildEnvironment, docnames: Iterable[str], other: BuildEnvironment) -> None: - warnings.warn('merge_info() is deprecated.', RemovedInSphinx40Warning) + warnings.warn('merge_info() is deprecated.', RemovedInSphinx40Warning, stacklevel=2) if not hasattr(other, 'todo_all_todos'): return if not hasattr(env, 'todo_all_todos'): diff --git a/sphinx/parsers.py b/sphinx/parsers.py index 3974d1c66..6a07d1801 100644 --- a/sphinx/parsers.py +++ b/sphinx/parsers.py @@ -64,7 +64,7 @@ class Parser(docutils.parsers.Parser): @property def app(self) -> "Sphinx": - warnings.warn('parser.app is deprecated.', RemovedInSphinx50Warning) + warnings.warn('parser.app is deprecated.', RemovedInSphinx50Warning, stacklevel=2) return self._app diff --git a/sphinx/pycode/__init__.py b/sphinx/pycode/__init__.py index 0a6ff5214..4879fb349 100644 --- a/sphinx/pycode/__init__.py +++ b/sphinx/pycode/__init__.py @@ -133,7 +133,7 @@ class ModuleAnalyzer: pos = source.tell() if not decoded: warnings.warn('decode option for ModuleAnalyzer is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) self._encoding, _ = tokenize.detect_encoding(source.readline) source.seek(pos) self.code = source.read().decode(self._encoding) @@ -185,5 +185,5 @@ class ModuleAnalyzer: @property def encoding(self) -> str: warnings.warn('ModuleAnalyzer.encoding is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) return self._encoding diff --git a/sphinx/roles.py b/sphinx/roles.py index ff24fcf55..57d11c269 100644 --- a/sphinx/roles.py +++ b/sphinx/roles.py @@ -574,7 +574,7 @@ def index_role(typ: str, rawtext: str, text: str, lineno: int, inliner: Inliner, class Index(ReferenceRole): def run(self) -> Tuple[List[Node], List[system_message]]: - warnings.warn('Index role is deprecated.', RemovedInSphinx40Warning) + warnings.warn('Index role is deprecated.', RemovedInSphinx40Warning, stacklevel=2) target_id = 'index-%s' % self.env.new_serialno('index') if self.has_explicit_title: # if an explicit target is given, process it as a full entry diff --git a/sphinx/search/__init__.py b/sphinx/search/__init__.py index d9853ff06..f9bbe0590 100644 --- a/sphinx/search/__init__.py +++ b/sphinx/search/__init__.py @@ -203,7 +203,7 @@ class WordCollector(nodes.NodeVisitor): def is_meta_keywords(self, node: addnodes.meta, nodetype: Any = None) -> bool: if nodetype is not None: warnings.warn('"nodetype" argument for WordCollector.is_meta_keywords() ' - 'is deprecated.', RemovedInSphinx40Warning) + 'is deprecated.', RemovedInSphinx40Warning, stacklevel=2) if isinstance(node, addnodes.meta) and node.get('name') == 'keywords': meta_lang = node.get('lang') diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index 12ae051f1..73d25a8f6 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -110,7 +110,7 @@ def get_matching_docs(dirname: str, suffixes: List[str], Exclude files and dirs matching a pattern in *exclude_patterns*. """ warnings.warn('get_matching_docs() is now deprecated. Use get_matching_files() instead.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) suffixpatterns = ['*' + s for s in suffixes] for filename in get_matching_files(dirname, exclude_matchers): for suffixpattern in suffixpatterns: @@ -315,7 +315,7 @@ _coding_re = re.compile(r'coding[:=]\s*([-\w.]+)') def detect_encoding(readline: Callable[[], bytes]) -> str: """Like tokenize.detect_encoding() from Py3k, but a bit simplified.""" warnings.warn('sphinx.util.detect_encoding() is deprecated', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) def read_or_stop() -> bytes: try: diff --git a/sphinx/util/compat.py b/sphinx/util/compat.py index 0135899eb..4923343ae 100644 --- a/sphinx/util/compat.py +++ b/sphinx/util/compat.py @@ -46,7 +46,7 @@ class IndexEntriesMigrator(SphinxTransform): if len(entries) == 4: source, line = get_source_line(node) warnings.warn('An old styled index node found: %r at (%s:%s)' % - (node, source, line), RemovedInSphinx40Warning) + (node, source, line), RemovedInSphinx40Warning, stacklevel=2) node['entries'][i] = entries + (None,) diff --git a/sphinx/util/docfields.py b/sphinx/util/docfields.py index 699738888..c07bc7f66 100644 --- a/sphinx/util/docfields.py +++ b/sphinx/util/docfields.py @@ -224,12 +224,12 @@ class DocFieldTransformer: except Exception: # for 3rd party extensions directly calls this transformer. warnings.warn('DocFieldTransformer expects given directive object is a subclass ' - 'of ObjectDescription.', RemovedInSphinx40Warning) + 'of ObjectDescription.', RemovedInSphinx40Warning, stacklevel=2) self.typemap = self.preprocess_fieldtypes(directive.__class__.doc_field_types) def preprocess_fieldtypes(self, types: List[Field]) -> Dict[str, Tuple[Field, bool]]: warnings.warn('DocFieldTransformer.preprocess_fieldtypes() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) typemap = {} for fieldtype in types: for name in fieldtype.names: diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 9eb05b29b..c81edc949 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -58,7 +58,7 @@ def getargspec(func: Callable) -> Any: """Like inspect.getfullargspec but supports bound methods, and wrapped methods.""" warnings.warn('sphinx.ext.inspect.getargspec() is deprecated', - RemovedInSphinx50Warning) + RemovedInSphinx50Warning, stacklevel=2) # On 3.5+, signature(int) or similar raises ValueError. On 3.4, it # succeeds with a bogus signature. We want a TypeError uniformly, to # match historical behavior. @@ -329,7 +329,7 @@ def safe_getattr(obj: Any, name: str, *defargs: Any) -> Any: def safe_getmembers(object: Any, predicate: Callable[[str], bool] = None, attr_getter: Callable = safe_getattr) -> List[Tuple[str, Any]]: """A version of inspect.getmembers() that uses safe_getattr().""" - warnings.warn('safe_getmembers() is deprecated', RemovedInSphinx40Warning) + warnings.warn('safe_getmembers() is deprecated', RemovedInSphinx40Warning, stacklevel=2) results = [] # type: List[Tuple[str, Any]] for key in dir(object): @@ -555,7 +555,7 @@ class Signature: def __init__(self, subject: Callable, bound_method: bool = False, has_retval: bool = True) -> None: warnings.warn('sphinx.util.inspect.Signature() is deprecated', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) # check subject is not a built-in class (ex. int, str) if (isinstance(subject, type) and diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py index bca6e0bfc..33ce8e4a9 100644 --- a/sphinx/util/nodes.py +++ b/sphinx/util/nodes.py @@ -280,7 +280,7 @@ def extract_messages(doctree: Element) -> Iterable[Tuple[Element, str]]: def find_source_node(node: Element) -> str: warnings.warn('find_source_node() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) return get_node_source(node) diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index 248abd0e7..23f5b0137 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -86,7 +86,7 @@ def ensuredir(path: str) -> None: def walk(top: str, topdown: bool = True, followlinks: bool = False) -> Iterator[Tuple[str, List[str], List[str]]]: # NOQA warnings.warn('sphinx.util.osutil.walk() is deprecated for removal. ' 'Please use os.walk() instead.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) return os.walk(top, topdown=topdown, followlinks=followlinks) @@ -178,7 +178,7 @@ def abspath(pathdir: str) -> str: def getcwd() -> str: warnings.warn('sphinx.util.osutil.getcwd() is deprecated. ' 'Please use os.getcwd() instead.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) return os.getcwd() diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 9390ba5de..e3ddedccf 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -96,7 +96,7 @@ class LaTeXWriter(writers.Writer): visitor = self.builder.create_translator(self.document, self.builder, self.theme) except TypeError: warnings.warn('LaTeXTranslator now takes 3rd argument; "theme".', - RemovedInSphinx50Warning) + RemovedInSphinx50Warning, stacklevel=2) visitor = self.builder.create_translator(self.document, self.builder) self.document.walkabout(visitor) @@ -292,7 +292,7 @@ class LaTeXTranslator(SphinxTranslator): if theme is None: warnings.warn('LaTeXTranslator now takes 3rd argument; "theme".', - RemovedInSphinx50Warning) + RemovedInSphinx50Warning, stacklevel=2) # flags self.in_title = 0 @@ -2072,7 +2072,7 @@ class LaTeXTranslator(SphinxTranslator): def babel_defmacro(self, name: str, definition: str) -> str: warnings.warn('babel_defmacro() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) if self.elements['babel']: prefix = '\\addto\\extras%s{' % self.babel.get_language() @@ -2085,7 +2085,7 @@ class LaTeXTranslator(SphinxTranslator): def generate_numfig_format(self, builder: "LaTeXBuilder") -> str: warnings.warn('generate_numfig_format() is deprecated.', - RemovedInSphinx40Warning) + RemovedInSphinx40Warning, stacklevel=2) ret = [] # type: List[str] figure = self.builder.config.numfig_format['figure'].split('%s', 1) if len(figure) == 1: |