summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-06-15 23:39:44 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-06-15 23:39:44 +0900
commit5d42659e3336329367c559c6d9be7b0bdfeb6687 (patch)
tree5d558a896aed0b403b5e8c5ecea0d85285fda34a
parentaf50bfcdf66aa419df3a474c15e665371dd7baf5 (diff)
parentd2f0c8356850b07b7cd37a266cb5487a2e51c71c (diff)
downloadsphinx-git-5d42659e3336329367c559c6d9be7b0bdfeb6687.tar.gz
Merge branch '2.0'
-rw-r--r--CHANGES36
-rw-r--r--CONTRIBUTING.rst2
-rw-r--r--doc/extdev/deprecated.rst36
-rw-r--r--doc/usage/extensions/graphviz.rst20
-rw-r--r--setup.cfg3
-rw-r--r--sphinx/builders/__init__.py131
-rw-r--r--sphinx/builders/_epub_base.py106
-rw-r--r--sphinx/builders/applehelp.py10
-rw-r--r--sphinx/builders/changes.py28
-rw-r--r--sphinx/builders/devhelp.py11
-rw-r--r--sphinx/builders/dirhtml.py19
-rw-r--r--sphinx/builders/dummy.py31
-rw-r--r--sphinx/builders/epub3.py40
-rw-r--r--sphinx/builders/gettext.py75
-rw-r--r--sphinx/builders/html.py203
-rw-r--r--sphinx/builders/htmlhelp.py11
-rw-r--r--sphinx/builders/latex/__init__.py85
-rw-r--r--sphinx/builders/latex/transforms.py122
-rw-r--r--sphinx/builders/latex/util.py15
-rw-r--r--sphinx/builders/linkcheck.py54
-rw-r--r--sphinx/builders/manpage.py30
-rw-r--r--sphinx/builders/qthelp.py10
-rw-r--r--sphinx/builders/singlehtml.py47
-rw-r--r--sphinx/builders/texinfo.py45
-rw-r--r--sphinx/builders/text.py30
-rw-r--r--sphinx/builders/xml.py32
-rw-r--r--sphinx/cmd/quickstart.py2
-rw-r--r--sphinx/directives/__init__.py43
-rw-r--r--sphinx/directives/code.py68
-rw-r--r--sphinx/directives/other.py46
-rw-r--r--sphinx/directives/patches.py35
-rw-r--r--sphinx/ext/autodoc/__init__.py13
-rw-r--r--sphinx/ext/autosummary/__init__.py1
-rw-r--r--sphinx/ext/autosummary/generate.py25
-rw-r--r--sphinx/ext/graphviz.py5
-rw-r--r--sphinx/ext/napoleon/docstring.py5
-rw-r--r--sphinx/ext/todo.py158
-rw-r--r--sphinx/locale/ar/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/bn/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/ca/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/cak/LC_MESSAGES/sphinx.po4
-rw-r--r--sphinx/locale/cs/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/cy/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/da/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/de/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/el/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/eo/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/es/LC_MESSAGES/sphinx.po4
-rw-r--r--sphinx/locale/et/LC_MESSAGES/sphinx.po4
-rw-r--r--sphinx/locale/eu/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/fa/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/fi/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/fr/LC_MESSAGES/sphinx.po4
-rw-r--r--sphinx/locale/he/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/hi/LC_MESSAGES/sphinx.po4
-rw-r--r--sphinx/locale/hi_IN/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/hr/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/hu/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/id/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/it/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/ja/LC_MESSAGES/sphinx.po4
-rw-r--r--sphinx/locale/ko/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/lt/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/lv/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/mk/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/nb_NO/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/ne/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/nl/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/pl/LC_MESSAGES/sphinx.po4
-rw-r--r--sphinx/locale/pt/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/pt_BR/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/pt_PT/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/ro/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/ru/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/si/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/sk/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/sl/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/sphinx.pot2
-rw-r--r--sphinx/locale/sr/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/sr@latin/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/sr_RS/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/sv/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/ta/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/tr/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/uk_UA/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/ur/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/vi/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/locale/zh_CN/LC_MESSAGES/sphinx.po4
-rw-r--r--sphinx/locale/zh_TW/LC_MESSAGES/sphinx.po2
-rw-r--r--sphinx/pycode/parser.py11
-rw-r--r--sphinx/util/docutils.py20
-rw-r--r--sphinx/util/typing.py2
-rw-r--r--tests/roots/test-ext-autodoc/target/module.py4
-rw-r--r--tests/test_autodoc.py24
-rw-r--r--tests/test_ext_napoleon_docstring.py4
-rw-r--r--tests/test_pycode_parser.py15
96 files changed, 806 insertions, 1027 deletions
diff --git a/CHANGES b/CHANGES
index 4591926be..742649694 100644
--- a/CHANGES
+++ b/CHANGES
@@ -33,9 +33,20 @@ Incompatible changes
Deprecated
----------
+* The ``info`` and ``warn`` arguments of
+ ``sphinx.ext.autosummary.generate.generate_autosummary_docs()``
+* ``sphinx.ext.autosummary.generate._simple_info()``
+* ``sphinx.ext.autosummary.generate._simple_warn()``
+* ``sphinx.ext.todo.merge_info()``
+* ``sphinx.ext.todo.process_todo_nodes()``
+* ``sphinx.ext.todo.process_todos()``
+* ``sphinx.ext.todo.purge_todos()``
+
Features added
--------------
+* #5124: graphviz: ``:graphviz_dot:`` option is renamed to ``:layout:``
+
Bugs fixed
----------
@@ -43,11 +54,12 @@ Bugs fixed
* #1125: html theme: scrollbar is hard to see on classic theme and macOS
* #5502: linkcheck: Consider HTTP 503 response as not an error
* #6439: Make generated download links reproducible
+* #6486: UnboundLocalError is raised if broken extension installed
Testing
--------
-Release 2.1.1 (in development)
+Release 2.1.2 (in development)
==============================
Dependencies
@@ -65,13 +77,29 @@ Features added
Bugs fixed
----------
+Testing
+--------
+
+Release 2.1.1 (released Jun 10, 2019)
+=====================================
+
+Incompatible changes
+--------------------
+
+* #6447: autodoc: Stop to generate document for undocumented module variables
+
+Bugs fixed
+----------
+
* #6442: LaTeX: admonitions of :rst:dir:`note` type can get separated from
immediately preceding section title by pagebreak
* #6448: autodoc: crashed when autodocumenting classes with ``__slots__ = None``
+* #6451: autodoc: generates docs for "optional import"ed modules as variables
* #6452: autosummary: crashed when generating document of properties
-
-Testing
---------
+* #6455: napoleon: docstrings for properties are not processed
+* #6436: napoleon: "Unknown target name" error if variable name ends with
+ underscore
+* #6440: apidoc: missing blank lines between modules
Release 2.1.0 (released Jun 02, 2019)
=====================================
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index 1807d3998..8c74b184a 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -250,7 +250,7 @@ the source and the compiled catalogs.
When a new locale is submitted, add a new directory with the ISO 639-1 language
identifier and put ``sphinx.po`` in there. Don't forget to update the possible
-values for :confval:`language` in ``doc/config.rst``.
+values for :confval:`language` in ``doc/usage/configuration.rst``.
The Sphinx core messages can also be translated on `Transifex
<https://www.transifex.com/>`_. There exists a client tool named ``tx`` in the
diff --git a/doc/extdev/deprecated.rst b/doc/extdev/deprecated.rst
index 38fae288c..f83235b92 100644
--- a/doc/extdev/deprecated.rst
+++ b/doc/extdev/deprecated.rst
@@ -26,6 +26,42 @@ The following is a list of deprecated interfaces.
- (will be) Removed
- Alternatives
+ * - The ``info`` and ``warn`` arguments of
+ ``sphinx.ext.autosummary.generate.generate_autosummary_docs()``
+ - 2.2
+ - 4.0
+ - ``logging.info()`` and ``logging.warning()``
+
+ * - ``sphinx.ext.autosummary.generate._simple_info()``
+ - 2.2
+ - 4.0
+ - ``logging.info()``
+
+ * - ``sphinx.ext.autosummary.generate._simple_warn()``
+ - 2.2
+ - 4.0
+ - ``logging.warning()``
+
+ * - ``sphinx.ext.todo.merge_info()``
+ - 2.2
+ - 4.0
+ - ``sphinx.ext.todo.TodoDomain``
+
+ * - ``sphinx.ext.todo.process_todo_nodes()``
+ - 2.2
+ - 4.0
+ - ``sphinx.ext.todo.TodoDomain``
+
+ * - ``sphinx.ext.todo.process_todos()``
+ - 2.2
+ - 4.0
+ - ``sphinx.ext.todo.TodoDomain``
+
+ * - ``sphinx.ext.todo.purge_todos()``
+ - 2.2
+ - 4.0
+ - ``sphinx.ext.todo.TodoDomain``
+
* - ``sphinx.builders.latex.LaTeXBuilder.apply_transforms()``
- 2.1
- 4.0
diff --git a/doc/usage/extensions/graphviz.rst b/doc/usage/extensions/graphviz.rst
index e5633c481..dd21b8214 100644
--- a/doc/usage/extensions/graphviz.rst
+++ b/doc/usage/extensions/graphviz.rst
@@ -63,13 +63,17 @@ It adds these directives:
.. versionadded:: 1.1
- .. rst:directive:option:: graphviz_dot: dot command of the graph
+ .. rst:directive:option:: layout: layout type of the graph
:type: text
- The graphviz command (ex. ``dot``, ``neato`` and so on) for rendering the
- graph. By default, :confval:`graphviz_dot` is used.
+ The layout of the graph (ex. ``dot``, ``neato`` and so on). A path to the
+ graphviz commands are also allowed. By default, :confval:`graphviz_dot`
+ is used.
.. versionadded:: 1.4
+ .. versionchanged:: 2.2
+
+ Renamed from ``graphviz_dot``
.. rst:directive:option:: name: label
:type: text
@@ -114,10 +118,13 @@ It adds these directives:
.. versionadded:: 1.1
- .. rst:directive:option:: graphviz_dot: dot command of the graph
+ .. rst:directive:option:: layout: layout type of the graph
:type: text
.. versionadded:: 1.4
+ .. versionchanged:: 2.2
+
+ Renamed from ``graphviz_dot``
.. rst:directive:option:: name: label
:type: text
@@ -156,10 +163,13 @@ It adds these directives:
.. versionadded:: 1.1
- .. rst:directive:option:: graphviz_dot: dot command of the graph
+ .. rst:directive:option:: layout: layout type of the graph
:type: text
.. versionadded:: 1.4
+ .. versionchanged:: 2.2
+
+ Renamed from ``graphviz_dot``
.. rst:directive:option:: name: label
:type: text
diff --git a/setup.cfg b/setup.cfg
index c91a31879..1f5bbd1cd 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -5,9 +5,6 @@ license_file = LICENSE
tag_build = .dev
tag_date = true
-[bdist_wheel]
-universal = 1
-
[aliases]
release = egg_info -Db ''
upload = upload --sign --identity=36580288
diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py
index 8eaa0e215..546b9b0a8 100644
--- a/sphinx/builders/__init__.py
+++ b/sphinx/builders/__init__.py
@@ -11,22 +11,27 @@
import pickle
import time
from os import path
+from typing import Any, Dict, Iterable, List, Sequence, Set, Tuple, Type, Union
from docutils import nodes
+from docutils.nodes import Node
-from sphinx.environment import CONFIG_OK, CONFIG_CHANGED_REASON
+from sphinx.config import Config
+from sphinx.environment import BuildEnvironment, CONFIG_OK, CONFIG_CHANGED_REASON
from sphinx.environment.adapters.asset import ImageAdapter
from sphinx.errors import SphinxError
+from sphinx.events import EventManager
from sphinx.io import read_doc
from sphinx.locale import __
from sphinx.util import import_object, logging, rst, progress_message, status_iterator
from sphinx.util.build_phase import BuildPhase
from sphinx.util.console import bold # type: ignore
from sphinx.util.docutils import sphinx_domains
-from sphinx.util.i18n import CatalogRepository, docname_to_domain
+from sphinx.util.i18n import CatalogInfo, CatalogRepository, docname_to_domain
from sphinx.util.osutil import SEP, ensuredir, relative_uri, relpath
from sphinx.util.parallel import ParallelTasks, SerialTasks, make_chunks, \
parallel_available
+from sphinx.util.tags import Tags
# side effect: registers roles and directives
from sphinx import roles # noqa
@@ -39,13 +44,7 @@ except ImportError:
if False:
# For type annotation
- from typing import Any, Dict, Iterable, List, Sequence, Set, Tuple, Type, Union # NOQA
- from sphinx.application import Sphinx # NOQA
- from sphinx.config import Config # NOQA
- from sphinx.environment import BuildEnvironment # NOQA
- from sphinx.events import EventManager # NOQA
- from sphinx.util.i18n import CatalogInfo # NOQA
- from sphinx.util.tags import Tags # NOQA
+ from sphinx.application import Sphinx
logger = logging.getLogger(__name__)
@@ -84,8 +83,7 @@ class Builder:
#: The builder supports data URIs or not.
supported_data_uri_images = False
- def __init__(self, app):
- # type: (Sphinx) -> None
+ def __init__(self, app: "Sphinx") -> None:
self.srcdir = app.srcdir
self.confdir = app.confdir
self.outdir = app.outdir
@@ -113,20 +111,17 @@ class Builder:
self.parallel_ok = False
self.finish_tasks = None # type: Any
- def set_environment(self, env):
- # type: (BuildEnvironment) -> None
+ def set_environment(self, env: BuildEnvironment) -> None:
"""Store BuildEnvironment object."""
self.env = env
self.env.set_versioning_method(self.versioning_method,
self.versioning_compare)
- def get_translator_class(self, *args):
- # type: (Any) -> Type[nodes.NodeVisitor]
+ def get_translator_class(self, *args) -> Type[nodes.NodeVisitor]:
"""Return a class of translator."""
return self.app.registry.get_translator_class(self)
- def create_translator(self, *args):
- # type: (Any) -> nodes.NodeVisitor
+ def create_translator(self, *args) -> nodes.NodeVisitor:
"""Return an instance of translator.
This method returns an instance of ``default_translator_class`` by default.
@@ -135,15 +130,13 @@ class Builder:
return self.app.registry.create_translator(self, *args)
# helper methods
- def init(self):
- # type: () -> None
+ def init(self) -> None:
"""Load necessary templates and perform initialization. The default
implementation does nothing.
"""
pass
- def create_template_bridge(self):
- # type: () -> None
+ def create_template_bridge(self) -> None:
"""Return the template bridge configured."""
if self.config.template_bridge:
self.templates = import_object(self.config.template_bridge,
@@ -152,8 +145,7 @@ class Builder:
from sphinx.jinja2glue import BuiltinTemplateLoader
self.templates = BuiltinTemplateLoader()
- def get_target_uri(self, docname, typ=None):
- # type: (str, str) -> str
+ def get_target_uri(self, docname: str, typ: str = None) -> str:
"""Return the target URI for a document name.
*typ* can be used to qualify the link characteristic for individual
@@ -161,8 +153,7 @@ class Builder:
"""
raise NotImplementedError
- def get_relative_uri(self, from_, to, typ=None):
- # type: (str, str, str) -> str
+ def get_relative_uri(self, from_: str, to: str, typ: str = None) -> str:
"""Return a relative URI between two source filenames.
May raise environment.NoUri if there's no way to return a sensible URI.
@@ -170,8 +161,7 @@ class Builder:
return relative_uri(self.get_target_uri(from_),
self.get_target_uri(to, typ))
- def get_outdated_docs(self):
- # type: () -> Union[str, Iterable[str]]
+ def get_outdated_docs(self) -> Union[str, Iterable[str]]:
"""Return an iterable of output files that are outdated, or a string
describing what an update build will build.
@@ -181,13 +171,11 @@ class Builder:
"""
raise NotImplementedError
- def get_asset_paths(self):
- # type: () -> List[str]
+ def get_asset_paths(self) -> List[str]:
"""Return list of paths for assets (ex. templates, CSS, etc.)."""
return []
- def post_process_images(self, doctree):
- # type: (nodes.Node) -> None
+ def post_process_images(self, doctree: Node) -> None:
"""Pick the best candidate for all image URIs."""
images = ImageAdapter(self.env)
for node in doctree.traverse(nodes.image):
@@ -220,13 +208,11 @@ class Builder:
# compile po methods
- def compile_catalogs(self, catalogs, message):
- # type: (Set[CatalogInfo], str) -> None
+ def compile_catalogs(self, catalogs: Set[CatalogInfo], message: str) -> None:
if not self.config.gettext_auto_build:
return
- def cat2relpath(cat):
- # type: (CatalogInfo) -> str
+ def cat2relpath(cat: CatalogInfo) -> str:
return relpath(cat.mo_path, self.env.srcdir).replace(path.sep, SEP)
logger.info(bold(__('building [mo]: ')) + message)
@@ -235,17 +221,14 @@ class Builder:
stringify_func=cat2relpath):
catalog.write_mo(self.config.language)
- def compile_all_catalogs(self):
- # type: () -> None
+ def compile_all_catalogs(self) -> None:
repo = CatalogRepository(self.srcdir, self.config.locale_dirs,
self.config.language, self.config.source_encoding)
message = __('all of %d po files') % len(list(repo.catalogs))
self.compile_catalogs(set(repo.catalogs), message)
- def compile_specific_catalogs(self, specified_files):
- # type: (List[str]) -> None
- def to_domain(fpath):
- # type: (str) -> str
+ def compile_specific_catalogs(self, specified_files: List[str]) -> None:
+ def to_domain(fpath: str) -> str:
docname = self.env.path2doc(path.abspath(fpath))
if docname:
return docname_to_domain(docname, self.config.gettext_compact)
@@ -262,8 +245,7 @@ class Builder:
message = __('targets for %d po files that are specified') % len(catalogs)
self.compile_catalogs(catalogs, message)
- def compile_update_catalogs(self):
- # type: () -> None
+ def compile_update_catalogs(self) -> None:
repo = CatalogRepository(self.srcdir, self.config.locale_dirs,
self.config.language, self.config.source_encoding)
catalogs = {c for c in repo.catalogs if c.is_outdated()}
@@ -272,13 +254,11 @@ class Builder:
# build methods
- def build_all(self):
- # type: () -> None
+ def build_all(self) -> None:
"""Build all source files."""
self.build(None, summary=__('all source files'), method='all')
- def build_specific(self, filenames):
- # type: (List[str]) -> None
+ def build_specific(self, filenames: List[str]) -> None:
"""Only rebuild as much as needed for changes in the *filenames*."""
# bring the filenames to the canonical format, that is,
# relative to the source directory and without source_suffix.
@@ -306,8 +286,7 @@ class Builder:
self.build(to_write, method='specific',
summary=__('%d source files given on command line') % len(to_write))
- def build_update(self):
- # type: () -> None
+ def build_update(self) -> None:
"""Only rebuild what was changed or added since last build."""
to_build = self.get_outdated_docs()
if isinstance(to_build, str):
@@ -318,8 +297,7 @@ class Builder:
summary=__('targets for %d source files that are out of date') %
len(to_build))
- def build(self, docnames, summary=None, method='update'):
- # type: (Iterable[str], str, str) -> None
+ def build(self, docnames: Iterable[str], summary: str = None, method: str = 'update') -> None: # NOQA
"""Main build method.
First updates the environment, and then calls :meth:`write`.
@@ -387,8 +365,7 @@ class Builder:
# wait for all tasks
self.finish_tasks.join()
- def read(self):
- # type: () -> List[str]
+ def read(self) -> List[str]:
"""(Re-)read all files new or changed since last update.
Store all environment docnames in the canonical format (ie using SEP as
@@ -450,8 +427,7 @@ class Builder:
return sorted(docnames)
- def _read_serial(self, docnames):
- # type: (List[str]) -> None
+ def _read_serial(self, docnames: List[str]) -> None:
for docname in status_iterator(docnames, __('reading sources... '), "purple",
len(docnames), self.app.verbosity):
# remove all inventory entries for that file
@@ -459,23 +435,20 @@ class Builder:
self.env.clear_doc(docname)
self.read_doc(docname)
- def _read_parallel(self, docnames, nproc):
- # type: (List[str], int) -> None
+ def _read_parallel(self, docnames: List[str], nproc: int) -> None:
# clear all outdated docs at once
for docname in docnames:
self.events.emit('env-purge-doc', self.env, docname)
self.env.clear_doc(docname)
- def read_process(docs):
- # type: (List[str]) -> bytes
+ def read_process(docs: List[str]) -> bytes:
self.env.app = self.app
for docname in docs:
self.read_doc(docname)
# allow pickling self to send it back
return pickle.dumps(self.env, pickle.HIGHEST_PROTOCOL)
- def merge(docs, otherenv):
- # type: (List[str], bytes) -> None
+ def merge(docs: List[str], otherenv: bytes) -> None:
env = pickle.loads(otherenv)
self.env.merge_info_from(docs, env, self.app)
@@ -490,8 +463,7 @@ class Builder:
logger.info(bold(__('waiting for workers...')))
tasks.join()
- def read_doc(self, docname):
- # type: (str) -> None
+ def read_doc(self, docname: str) -> None:
"""Parse a file and add/update inventory entries for the doctree."""
self.env.prepare_settings(docname)
@@ -516,8 +488,7 @@ class Builder:
self.write_doctree(docname, doctree)
- def write_doctree(self, docname, doctree):
- # type: (str, nodes.document) -> None
+ def write_doctree(self, docname: str, doctree: nodes.document) -> None:
"""Write the doctree to a file."""
# make it picklable
doctree.reporter = None
@@ -531,8 +502,7 @@ class Builder:
with open(doctree_filename, 'wb') as f:
pickle.dump(doctree, f, pickle.HIGHEST_PROTOCOL)
- def write(self, build_docnames, updated_docnames, method='update'):
- # type: (Iterable[str], Sequence[str], str) -> None
+ def write(self, build_docnames: Iterable[str], updated_docnames: Sequence[str], method: str = 'update') -> None: # NOQA
if build_docnames is None or build_docnames == ['__all__']:
# build_all
build_docnames = self.env.found_docs
@@ -561,8 +531,7 @@ class Builder:
else:
self._write_serial(sorted(docnames))
- def _write_serial(self, docnames):
- # type: (Sequence[str]) -> None
+ def _write_serial(self, docnames: Sequence[str]) -> None:
with logging.pending_warnings():
for docname in status_iterator(docnames, __('writing output... '), "darkgreen",
len(docnames), self.app.verbosity):
@@ -572,10 +541,8 @@ class Builder:
self.write_doc_serialized(docname, doctree)
self.write_doc(docname, doctree)
- def _write_parallel(self, docnames, nproc):
- # type: (Sequence[str], int) -> None
- def write_process(docs):
- # type: (List[Tuple[str, nodes.document]]) -> None
+ def _write_parallel(self, docnames: Sequence[str], nproc: int) -> None:
+ def write_process(docs: List[Tuple[str, nodes.document]]) -> None:
self.app.phase = BuildPhase.WRITING
for docname, doctree in docs:
self.write_doc(docname, doctree)
@@ -605,41 +572,35 @@ class Builder:
logger.info(bold(__('waiting for workers...')))
tasks.join()
- def prepare_writing(self, docnames):
- # type: (Set[str]) -> None
+ def prepare_writing(self, docnames: Set[str]) -> None:
"""A place where you can add logic before :meth:`write_doc` is run"""
raise NotImplementedError
- def write_doc(self, docname, doctree):
- # type: (str, nodes.document) -> None
+ def write_doc(self, docname: str, doctree: nodes.document) -> None:
"""Where you actually write something to the filesystem."""
raise NotImplementedError
- def write_doc_serialized(self, docname, doctree):
- # type: (str, nodes.document) -> None
+ def write_doc_serialized(self, docname: str, doctree: nodes.document) -> None:
"""Handle parts of write_doc that must be called in the main process
if parallel build is active.
"""
pass
- def finish(self):
- # type: () -> None
+ def finish(self) -> None:
"""Finish the building process.
The default implementation does nothing.
"""
pass
- def cleanup(self):
- # type: () -> None
+ def cleanup(self) -> None:
"""Cleanup any resources.
The default implementation does nothing.
"""
pass
- def get_builder_config(self, option, default):
- # type: (str, str) -> Any
+ def get_builder_config(self, option: str, default: str) -> Any:
"""Return a builder specific option.
This method allows customization of common builder settings by
diff --git a/sphinx/builders/_epub_base.py b/sphinx/builders/_epub_base.py
index 140f2748d..75e79936b 100644
--- a/sphinx/builders/_epub_base.py
+++ b/sphinx/builders/_epub_base.py
@@ -14,9 +14,11 @@ import re
import warnings
from collections import namedtuple
from os import path
+from typing import Any, Dict, List, Set, Tuple
from zipfile import ZIP_DEFLATED, ZIP_STORED, ZipFile
from docutils import nodes
+from docutils.nodes import Element, Node
from docutils.utils import smartquotes
from sphinx import addnodes
@@ -34,10 +36,6 @@ try:
except ImportError:
Image = None
-if False:
- # For type annotation
- from typing import Any, Dict, List, Set, Tuple # NOQA
-
logger = logging.getLogger(__name__)
@@ -93,8 +91,7 @@ Guide = namedtuple('Guide', ['type', 'title', 'uri'])
NavPoint = namedtuple('NavPoint', ['navpoint', 'playorder', 'text', 'refuri', 'children'])
-def sphinx_smarty_pants(t, language='en'):
- # type: (str, str) -> str
+def sphinx_smarty_pants(t: str, language: str = 'en') -> str:
t = t.replace('&quot;', '"')
t = smartquotes.educateDashesOldSchool(t)
t = smartquotes.educateQuotes(t, language)
@@ -145,8 +142,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
template_dir = ""
doctype = ""
- def init(self):
- # type: () -> None
+ def init(self) -> None:
super().init()
# the output files for epub must be .html only
self.out_suffix = '.xhtml'
@@ -157,17 +153,14 @@ class EpubBuilder(StandaloneHTMLBuilder):
self.use_index = self.get_builder_config('use_index', 'epub')
self.refnodes = [] # type: List[Dict[str, Any]]
- def create_build_info(self):
- # type: () -> BuildInfo
+ def create_build_info(self) -> BuildInfo:
return BuildInfo(self.config, self.tags, ['html', 'epub'])
- def get_theme_config(self):
- # type: () -> Tuple[str, Dict]
+ def get_theme_config(self) -> Tuple[str, Dict]:
return self.config.epub_theme, self.config.epub_theme_options
# generic support functions
- def make_id(self, name):
- # type: (str) -> str
+ def make_id(self, name: str) -> str:
# id_cache is intentionally mutable
"""Return a unique id for name."""
id = self.id_cache.get(name)
@@ -176,8 +169,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
self.id_cache[name] = id
return id
- def esc(self, name):
- # type: (str) -> str
+ def esc(self, name: str) -> str:
"""Replace all characters not allowed in text an attribute values."""
warnings.warn(
'%s.esc() is deprecated. Use html.escape() instead.' % self.__class__.__name__,
@@ -189,8 +181,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
name = name.replace('\'', '&#39;')
return name
- def get_refnodes(self, doctree, result):
- # type: (nodes.Node, List[Dict[str, Any]]) -> List[Dict[str, Any]]
+ def get_refnodes(self, doctree: Node, result: List[Dict[str, Any]]) -> List[Dict[str, Any]]: # NOQA
"""Collect section titles, their depth in the toc and the refuri."""
# XXX: is there a better way than checking the attribute
# toctree-l[1-8] on the parent node?
@@ -213,8 +204,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
result = self.get_refnodes(elem, result)
return result
- def check_refnodes(self, nodes):
- # type: (List[Dict[str, Any]]) -> None
+ def check_refnodes(self, nodes: List[Dict[str, Any]]) -> None:
appeared = set() # type: Set[str]
for node in nodes:
if node['refuri'] in appeared:
@@ -222,8 +212,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
else:
appeared.add(node['refuri'])
- def get_toc(self):
- # type: () -> None
+ def get_toc(self) -> None:
"""Get the total table of contents, containing the master_doc
and pre and post files not managed by sphinx.
"""
@@ -238,8 +227,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
item['refuri'] = master_dir + item['refuri']
self.toc_add_files(self.refnodes)
- def toc_add_files(self, refnodes):
- # type: (List[Dict[str, Any]]) -> None
+ def toc_add_files(self, refnodes: List[Dict[str, Any]]) -> None:
"""Add the master_doc, pre and post files to a list of refnodes.
"""
refnodes.insert(0, {
@@ -261,13 +249,11 @@ class EpubBuilder(StandaloneHTMLBuilder):
'text': ssp(html.escape(text))
})
- def fix_fragment(self, prefix, fragment):
- # type: (str, str) -> str
+ def fix_fragment(self, prefix: str, fragment: str) -> str:
"""Return a href/id attribute with colons replaced by hyphens."""
return prefix + fragment.replace(':', '-')
- def fix_ids(self, tree):
- # type: (nodes.document) -> None
+ def fix_ids(self, tree: nodes.document) -> None:
"""Replace colons with hyphens in href and id attributes.
Some readers crash because they interpret the part as a
@@ -286,7 +272,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
if ':' in node_id:
target['ids'][i] = self.fix_fragment('', node_id)
- next_node = target.next_node(siblings=True) # type: nodes.Node
+ next_node = target.next_node(siblings=True) # type: Node
if isinstance(next_node, nodes.Element):
for i, node_id in enumerate(next_node['ids']):
if ':' in node_id:
@@ -299,20 +285,17 @@ class EpubBuilder(StandaloneHTMLBuilder):
newids.append(self.fix_fragment('', id))
desc_signature.attributes['ids'] = newids
- def add_visible_links(self, tree, show_urls='inline'):
- # type: (nodes.document, str) -> None
+ def add_visible_links(self, tree: nodes.document, show_urls: str = 'inline') -> None:
"""Add visible link targets for external links"""
- def make_footnote_ref(doc, label):
- # type: (nodes.document, str) -> nodes.footnote_reference
+ def make_footnote_ref(doc: nodes.document, label: str) -> nodes.footnote_reference:
"""Create a footnote_reference node with children"""
footnote_ref = nodes.footnote_reference('[#]_')
footnote_ref.append(nodes.Text(label))
doc.note_autofootnote_ref(footnote_ref)
return footnote_ref
- def make_footnote(doc, label, uri):
- # type: (nodes.document, str, str) -> nodes.footnote
+ def make_footnote(doc: nodes.document, label: str, uri: str) -> nodes.footnote:
"""Create a footnote node with children"""
footnote = nodes.footnote(uri)
para = nodes.paragraph()
@@ -322,8 +305,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
doc.note_autofootnote(footnote)
return footnote
- def footnote_spot(tree):
- # type: (nodes.document) -> Tuple[nodes.Element, int]
+ def footnote_spot(tree: nodes.document) -> Tuple[Element, int]:
"""Find or create a spot to place footnotes.
The function returns the tuple (parent, index)."""
@@ -371,8 +353,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
footnote.add_backref(footnote_ref['ids'][0])
fn_idx += 1
- def write_doc(self, docname, doctree):
- # type: (str, nodes.document) -> None
+ def write_doc(self, docname: str, doctree: nodes.document) -> None:
"""Write one document file.
This method is overwritten in order to fix fragment identifiers
@@ -382,8 +363,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
self.add_visible_links(doctree, self.config.epub_show_urls)
super().write_doc(docname, doctree)
- def fix_genindex(self, tree):
- # type: (List[Tuple[str, List[Tuple[str, Any]]]]) -> None
+ def fix_genindex(self, tree: List[Tuple[str, List[Tuple[str, Any]]]]) -> None:
"""Fix href attributes for genindex pages."""
# XXX: modifies tree inline
# Logic modeled from themes/basic/genindex.html
@@ -401,14 +381,12 @@ class EpubBuilder(StandaloneHTMLBuilder):
subentrylinks[i] = (ismain,
self.fix_fragment(m.group(1), m.group(2)))
- def is_vector_graphics(self, filename):
- # type: (str) -> bool
+ def is_vector_graphics(self, filename: str) -> bool:
"""Does the filename extension indicate a vector graphic format?"""
ext = path.splitext(filename)[-1]
return ext in VECTOR_GRAPHICS_EXTENSIONS
- def copy_image_files_pil(self):
- # type: () -> None
+ def copy_image_files_pil(self) -> None:
"""Copy images using Pillow, the Python Imaging Libary.
The method tries to read and write the files with Pillow, converting
the format and resizing the image if necessary/possible.
@@ -447,8 +425,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
logger.warning(__('cannot write image file %r: %s'),
path.join(self.srcdir, src), err)
- def copy_image_files(self):
- # type: () -> None
+ def copy_image_files(self) -> None:
"""Copy image files to destination directory.
This overwritten method can use Pillow to convert image files.
"""
@@ -462,13 +439,11 @@ class EpubBuilder(StandaloneHTMLBuilder):
else:
super().copy_image_files()
- def copy_download_files(self):
- # type: () -> None
+ def copy_download_files(self) -> None:
pass
- def handle_page(self, pagename, addctx, templatename='page.html',
- outfilename=None, event_arg=None):
- # type: (str, Dict, str, str, Any) -> None
+ def handle_page(self, pagename: str, addctx: Dict, templatename: str = 'page.html',
+ outfilename: str = None, event_arg: Any = None) -> None:
"""Create a rendered page.
This method is overwritten for genindex pages in order to fix href link
@@ -481,8 +456,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
addctx['doctype'] = self.doctype
super().handle_page(pagename, addctx, templatename, outfilename, event_arg)
- def build_mimetype(self, outdir=None, outname='mimetype'):
- # type: (str, str) -> None
+ def build_mimetype(self, outdir: str = None, outname: str = 'mimetype') -> None:
"""Write the metainfo file mimetype."""
if outdir:
warnings.warn('The arguments of EpubBuilder.build_mimetype() is deprecated.',
@@ -494,8 +468,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
copy_asset_file(path.join(self.template_dir, 'mimetype'),
path.join(outdir, outname))
- def build_container(self, outdir=None, outname='META-INF/container.xml'):
- # type: (str, str) -> None
+ def build_container(self, outdir: str = None, outname: str = 'META-INF/container.xml') -> None: # NOQA
"""Write the metainfo file META-INF/container.xml."""
if outdir:
warnings.warn('The arguments of EpubBuilder.build_container() is deprecated.',
@@ -508,8 +481,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
ensuredir(path.dirname(filename))
copy_asset_file(path.join(self.template_dir, 'container.xml'), filename)
- def content_metadata(self):
- # type: () -> Dict[str, Any]
+ def content_metadata(self) -> Dict[str, Any]:
"""Create a dictionary with all metadata for the content.opf
file properly escaped.
"""
@@ -528,8 +500,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
metadata['guides'] = []
return metadata
- def build_content(self, outdir=None, outname='content.opf'):
- # type: (str, str) -> None
+ def build_content(self, outdir: str = None, outname: str = 'content.opf') -> None:
"""Write the metainfo file content.opf It contains bibliographic data,
a file list and the spine (the reading order).
"""
@@ -648,8 +619,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
path.join(outdir, outname),
metadata)
- def new_navpoint(self, node, level, incr=True):
- # type: (Dict[str, Any], int, bool) -> NavPoint
+ def new_navpoint(self, node: Dict[str, Any], level: int, incr: bool = True) -> NavPoint:
"""Create a new entry in the toc from the node at given level."""
# XXX Modifies the node
if incr:
@@ -658,8 +628,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
return NavPoint('navPoint%d' % self.tocid, self.playorder,
node['text'], node['refuri'], [])
- def build_navpoints(self, nodes):
- # type: (List[Dict[str, Any]]) -> List[NavPoint]
+ def build_navpoints(self, nodes: List[Dict[str, Any]]) -> List[NavPoint]:
"""Create the toc navigation structure.
Subelements of a node are nested inside the navpoint. For nested nodes
@@ -703,8 +672,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
return navstack[0].children
- def toc_metadata(self, level, navpoints):
- # type: (int, List[NavPoint]) -> Dict[str, Any]
+ def toc_metadata(self, level: int, navpoints: List[NavPoint]) -> Dict[str, Any]:
"""Create a dictionary with all metadata for the toc.ncx file
properly escaped.
"""
@@ -715,8 +683,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
metadata['navpoints'] = navpoints
return metadata
- def build_toc(self, outdir=None, outname='toc.ncx'):
- # type: (str, str) -> None
+ def build_toc(self, outdir: str = None, outname: str = 'toc.ncx') -> None:
"""Write the metainfo file toc.ncx."""
if outdir:
warnings.warn('The arguments of EpubBuilder.build_toc() is deprecated.',
@@ -743,8 +710,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
path.join(outdir, outname),
self.toc_metadata(level, navpoints))
- def build_epub(self, outdir=None, outname=None):
- # type: (str, str) -> None
+ def build_epub(self, outdir: str = None, outname: str = None) -> None:
"""Write the epub file.
It is a zip file with the mimetype file stored uncompressed as the first
diff --git a/sphinx/builders/applehelp.py b/sphinx/builders/applehelp.py
index 0ee50ff56..d7dd336ca 100644
--- a/sphinx/builders/applehelp.py
+++ b/sphinx/builders/applehelp.py
@@ -9,6 +9,7 @@
"""
import warnings
+from typing import Any, Dict
from sphinxcontrib.applehelp import (
AppleHelpCodeSigningFailed,
@@ -16,13 +17,9 @@ from sphinxcontrib.applehelp import (
AppleHelpBuilder,
)
+from sphinx.application import Sphinx
from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
-if False:
- # For type annotation
- from typing import Any, Dict # NOQA
- from sphinx.application import Sphinx # NOQA
-
deprecated_alias('sphinx.builders.applehelp',
{
@@ -33,8 +30,7 @@ deprecated_alias('sphinx.builders.applehelp',
RemovedInSphinx40Warning)
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
warnings.warn('sphinx.builders.applehelp has been moved to sphinxcontrib-applehelp.',
RemovedInSphinx40Warning)
app.setup_extension('sphinxcontrib.applehelp')
diff --git a/sphinx/builders/changes.py b/sphinx/builders/changes.py
index 3b169e493..a42215fad 100644
--- a/sphinx/builders/changes.py
+++ b/sphinx/builders/changes.py
@@ -10,9 +10,11 @@
import html
from os import path
+from typing import Any, Dict, List, Tuple
from typing import cast
from sphinx import package_dir
+from sphinx.application import Sphinx
from sphinx.builders import Builder
from sphinx.domains.changeset import ChangeSetDomain
from sphinx.locale import _, __
@@ -22,11 +24,6 @@ from sphinx.util.console import bold # type: ignore
from sphinx.util.fileutil import copy_asset_file
from sphinx.util.osutil import ensuredir, os_path
-if False:
- # For type annotation
- from typing import Any, Dict, List, Tuple # NOQA
- from sphinx.application import Sphinx # NOQA
-
logger = logging.getLogger(__name__)
@@ -38,15 +35,13 @@ class ChangesBuilder(Builder):
name = 'changes'
epilog = __('The overview file is in %(outdir)s.')
- def init(self):
- # type: () -> None
+ def init(self) -> None:
self.create_template_bridge()
theme_factory = HTMLThemeFactory(self.app)
self.theme = theme_factory.create('default')
self.templates.init(self, self.theme)
- def get_outdated_docs(self):
- # type: () -> str
+ def get_outdated_docs(self) -> str:
return self.outdir
typemap = {
@@ -55,8 +50,7 @@ class ChangesBuilder(Builder):
'deprecated': 'deprecated',
}
- def write(self, *ignored):
- # type: (Any) -> None
+ def write(self, *ignored) -> None:
version = self.config.version
domain = cast(ChangeSetDomain, self.env.get_domain('changeset'))
libchanges = {} # type: Dict[str, List[Tuple[str, str, int]]]
@@ -121,8 +115,7 @@ class ChangesBuilder(Builder):
'.. versionchanged:: %s' % version,
'.. deprecated:: %s' % version]
- def hl(no, line):
- # type: (int, str) -> str
+ def hl(no: int, line: str) -> str:
line = '<a name="L%s"> </a>' % no + html.escape(line)
for x in hltext:
if x in line:
@@ -155,21 +148,18 @@ class ChangesBuilder(Builder):
copy_asset_file(path.join(package_dir, 'themes', 'basic', 'static', 'basic.css'),
self.outdir)
- def hl(self, text, version):
- # type: (str, str) -> str
+ def hl(self, text: str, version: str) -> str:
text = html.escape(text)
for directive in ['versionchanged', 'versionadded', 'deprecated']:
text = text.replace('.. %s:: %s' % (directive, version),
'<b>.. %s:: %s</b>' % (directive, version))
return text
- def finish(self):
- # type: () -> None
+ def finish(self) -> None:
pass
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
app.add_builder(ChangesBuilder)
return {
diff --git a/sphinx/builders/devhelp.py b/sphinx/builders/devhelp.py
index 2306ddee2..17e861777 100644
--- a/sphinx/builders/devhelp.py
+++ b/sphinx/builders/devhelp.py
@@ -11,18 +11,14 @@
"""
import warnings
+from typing import Any, Dict
from sphinxcontrib.devhelp import DevhelpBuilder
+from sphinx.application import Sphinx
from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
-if False:
- # For type annotation
- from typing import Any, Dict # NOQA
- from sphinx.application import Sphinx # NOQA
-
-
deprecated_alias('sphinx.builders.devhelp',
{
'DevhelpBuilder': DevhelpBuilder,
@@ -30,8 +26,7 @@ deprecated_alias('sphinx.builders.devhelp',
RemovedInSphinx40Warning)
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
warnings.warn('sphinx.builders.devhelp has been moved to sphinxcontrib-devhelp.',
RemovedInSphinx40Warning)
app.setup_extension('sphinxcontrib.devhelp')
diff --git a/sphinx/builders/dirhtml.py b/sphinx/builders/dirhtml.py
index d5d61c273..40ec7b11f 100644
--- a/sphinx/builders/dirhtml.py
+++ b/sphinx/builders/dirhtml.py
@@ -9,17 +9,14 @@
"""
from os import path
+from typing import Any, Dict, Set
+from sphinx.application import Sphinx
from sphinx.builders.html import StandaloneHTMLBuilder
from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
from sphinx.util import logging
from sphinx.util.osutil import SEP, os_path
-if False:
- # For type annotation
- from typing import Any, Dict, Set # NOQA
- from sphinx.application import Sphinx # NOQA
-
logger = logging.getLogger(__name__)
@@ -31,16 +28,14 @@ class DirectoryHTMLBuilder(StandaloneHTMLBuilder):
"""
name = 'dirhtml'
- def get_target_uri(self, docname, typ=None):
- # type: (str, str) -> str
+ def get_target_uri(self, docname: str, typ: str = None) -> str:
if docname == 'index':
return ''
if docname.endswith(SEP + 'index'):
return docname[:-5] # up to sep
return docname + SEP
- def get_outfilename(self, pagename):
- # type: (str) -> str
+ def get_outfilename(self, pagename: str) -> str:
if pagename == 'index' or pagename.endswith(SEP + 'index'):
outfilename = path.join(self.outdir, os_path(pagename) +
self.out_suffix)
@@ -50,8 +45,7 @@ class DirectoryHTMLBuilder(StandaloneHTMLBuilder):
return outfilename
- def prepare_writing(self, docnames):
- # type: (Set[str]) -> None
+ def prepare_writing(self, docnames: Set[str]) -> None:
super().prepare_writing(docnames)
self.globalcontext['no_search_suffix'] = True
@@ -64,8 +58,7 @@ deprecated_alias('sphinx.builders.html',
RemovedInSphinx40Warning)
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
app.setup_extension('sphinx.builders.html')
app.add_builder(DirectoryHTMLBuilder)
diff --git a/sphinx/builders/dummy.py b/sphinx/builders/dummy.py
index d5ae94a82..33d2506ac 100644
--- a/sphinx/builders/dummy.py
+++ b/sphinx/builders/dummy.py
@@ -8,16 +8,14 @@
:license: BSD, see LICENSE for details.
"""
+from typing import Any, Dict, Set
+from docutils.nodes import Node
+
+from sphinx.application import Sphinx
from sphinx.builders import Builder
from sphinx.locale import __
-if False:
- # For type annotation
- from typing import Any, Dict, Set # NOQA
- from docutils import nodes # NOQA
- from sphinx.application import Sphinx # NOQA
-
class DummyBuilder(Builder):
name = 'dummy'
@@ -25,33 +23,26 @@ class DummyBuilder(Builder):
allow_parallel = True
- def init(self):
- # type: () -> None
+ def init(self) -> None:
pass
- def get_outdated_docs(self):
- # type: () -> Set[str]
+ def get_outdated_docs(self) -> Set[str]:
return self.env.found_docs
- def get_target_uri(self, docname, typ=None):
- # type: (str, str) -> str
+ def get_target_uri(self, docname: str, typ: str = None) -> str:
return ''
- def prepare_writing(self, docnames):
- # type: (Set[str]) -> None
+ def prepare_writing(self, docnames: Set[str]) -> None:
pass
- def write_doc(self, docname, doctree):
- # type: (str, nodes.Node) -> None
+ def write_doc(self, docname: str, doctree: Node) -> None:
pass
- def finish(self):
- # type: () -> None
+ def finish(self) -> None:
pass
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
app.add_builder(DummyBuilder)
return {
diff --git a/sphinx/builders/epub3.py b/sphinx/builders/epub3.py
index 9b3f58d7a..5d7121fe6 100644
--- a/sphinx/builders/epub3.py
+++ b/sphinx/builders/epub3.py
@@ -13,10 +13,12 @@ import html
import warnings
from collections import namedtuple
from os import path
+from typing import Any, Dict, List, Set, Tuple
from sphinx import package_dir
+from sphinx.application import Sphinx
from sphinx.builders import _epub_base
-from sphinx.config import ENUM
+from sphinx.config import Config, ENUM
from sphinx.deprecation import RemovedInSphinx40Warning
from sphinx.locale import __
from sphinx.util import logging, xmlname_checker
@@ -24,12 +26,6 @@ from sphinx.util.fileutil import copy_asset_file
from sphinx.util.i18n import format_date
from sphinx.util.osutil import make_filename
-if False:
- # For type annotation
- from typing import Any, Dict, List, Set, Tuple # NOQA
- from sphinx.application import Sphinx # NOQA
- from sphinx.config import Config # NOQA
-
logger = logging.getLogger(__name__)
@@ -75,8 +71,7 @@ class Epub3Builder(_epub_base.EpubBuilder):
use_meta_charset = True
# Finish by building the epub file
- def handle_finish(self):
- # type: () -> None
+ def handle_finish(self) -> None:
"""Create the metainfo files and finally the epub."""
self.get_toc()
self.build_mimetype()
@@ -86,13 +81,11 @@ class Epub3Builder(_epub_base.EpubBuilder):
self.build_toc()
self.build_epub()
- def validate_config_value(self):
- # type: () -> None
+ def validate_config_value(self) -> None:
warnings.warn('Epub3Builder.validate_config_value() is deprecated.',
RemovedInSphinx40Warning, stacklevel=2)
- def content_metadata(self):
- # type: () -> Dict
+ def content_metadata(self) -> Dict:
"""Create a dictionary with all metadata for the content.opf
file properly escaped.
"""
@@ -108,8 +101,7 @@ class Epub3Builder(_epub_base.EpubBuilder):
metadata['epub_version'] = self.config.epub_version
return metadata
- def prepare_writing(self, docnames):
- # type: (Set[str]) -> None
+ def prepare_writing(self, docnames: Set[str]) -> None:
super().prepare_writing(docnames)
writing_mode = self.config.epub_writing_mode
@@ -118,8 +110,7 @@ class Epub3Builder(_epub_base.EpubBuilder):
self.globalcontext['use_meta_charset'] = self.use_meta_charset
self.globalcontext['skip_ua_compatible'] = True
- def build_navlist(self, navnodes):
- # type: (List[Dict[str, Any]]) -> List[NavPoint]
+ def build_navlist(self, navnodes: List[Dict[str, Any]]) -> List[NavPoint]:
"""Create the toc navigation structure.
This method is almost same as build_navpoints method in epub.py.
@@ -161,8 +152,7 @@ class Epub3Builder(_epub_base.EpubBuilder):
return navstack[0].children
- def navigation_doc_metadata(self, navlist):
- # type: (List[NavPoint]) -> Dict
+ def navigation_doc_metadata(self, navlist: List[NavPoint]) -> Dict:
"""Create a dictionary with all metadata for the nav.xhtml file
properly escaped.
"""
@@ -172,8 +162,7 @@ class Epub3Builder(_epub_base.EpubBuilder):
metadata['navlist'] = navlist
return metadata
- def build_navigation_doc(self, outdir=None, outname='nav.xhtml'):
- # type: (str, str) -> None
+ def build_navigation_doc(self, outdir: str = None, outname: str = 'nav.xhtml') -> None:
"""Write the metainfo file nav.xhtml."""
if outdir:
warnings.warn('The arguments of Epub3Builder.build_navigation_doc() '
@@ -202,8 +191,7 @@ class Epub3Builder(_epub_base.EpubBuilder):
self.files.append(outname)
-def validate_config_values(app):
- # type: (Sphinx) -> None
+def validate_config_values(app: Sphinx) -> None:
if app.builder.name != 'epub':
return
@@ -242,8 +230,7 @@ def validate_config_values(app):
logger.warning(__('conf value "version" should not be empty for EPUB3'))
-def convert_epub_css_files(app, config):
- # type: (Sphinx, Config) -> None
+def convert_epub_css_files(app: Sphinx, config: Config) -> None:
"""This converts string styled epub_css_files to tuple styled one."""
epub_css_files = [] # type: List[Tuple[str, Dict]]
for entry in config.epub_css_files:
@@ -260,8 +247,7 @@ def convert_epub_css_files(app, config):
config.epub_css_files = epub_css_files # type: ignore
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
app.add_builder(Epub3Builder)
# config values
diff --git a/sphinx/builders/gettext.py b/sphinx/builders/gettext.py
index f26b831da..2beb4a5ce 100644
--- a/sphinx/builders/gettext.py
+++ b/sphinx/builders/gettext.py
@@ -14,27 +14,25 @@ from datetime import datetime, tzinfo, timedelta
from io import StringIO
from os import path, walk, getenv
from time import time
+from typing import Any, DefaultDict, Dict, Iterable, List, Set, Tuple, Union
from uuid import uuid4
+from docutils import nodes
+from docutils.nodes import Element
+
from sphinx import addnodes
+from sphinx.application import Sphinx
from sphinx.builders import Builder
from sphinx.domains.python import pairindextypes
from sphinx.errors import ThemeError
from sphinx.locale import __
from sphinx.util import split_index_msg, logging, status_iterator
from sphinx.util.console import bold # type: ignore
-from sphinx.util.i18n import docname_to_domain
+from sphinx.util.i18n import CatalogInfo, docname_to_domain
from sphinx.util.nodes import extract_messages, traverse_translatable_index
from sphinx.util.osutil import relpath, ensuredir, canon_path
from sphinx.util.tags import Tags
-if False:
- # For type annotation
- from typing import Any, DefaultDict, Dict, Iterable, List, Set, Tuple, Union # NOQA
- from docutils import nodes # NOQA
- from sphinx.application import Sphinx # NOQA
- from sphinx.util.i18n import CatalogInfo # NOQA
-
logger = logging.getLogger(__name__)
@@ -63,15 +61,13 @@ msgstr ""
class Catalog:
"""Catalog of translatable messages."""
- def __init__(self):
- # type: () -> None
+ def __init__(self) -> None:
self.messages = [] # type: List[str]
# retain insertion order, a la OrderedDict
self.metadata = OrderedDict() # type: Dict[str, List[Tuple[str, int, str]]]
# msgid -> file, line, uid
- def add(self, msg, origin):
- # type: (str, Union[nodes.Element, MsgOrigin]) -> None
+ def add(self, msg: str, origin: Union[Element, "MsgOrigin"]) -> None:
if not hasattr(origin, 'uid'):
# Nodes that are replicated like todo don't have a uid,
# however i18n is also unnecessary.
@@ -87,8 +83,7 @@ class MsgOrigin:
Origin holder for Catalog message origin.
"""
- def __init__(self, source, line):
- # type: (str, int) -> None
+ def __init__(self, source: str, line: int) -> None:
self.source = source
self.line = line
self.uid = uuid4().hex
@@ -100,8 +95,7 @@ class I18nTags(Tags):
To translate all text inside of only nodes, this class
always returns True value even if no tags are defined.
"""
- def eval_condition(self, condition):
- # type: (Any) -> bool
+ def eval_condition(self, condition: Any) -> bool:
return True
@@ -115,32 +109,26 @@ class I18nBuilder(Builder):
# be set by `gettext_uuid`
use_message_catalog = False
- def init(self):
- # type: () -> None
+ def init(self) -> None:
super().init()
self.env.set_versioning_method(self.versioning_method,
self.env.config.gettext_uuid)
self.tags = I18nTags()
self.catalogs = defaultdict(Catalog) # type: DefaultDict[str, Catalog]
- def get_target_uri(self, docname, typ=None):
- # type: (str, str) -> str
+ def get_target_uri(self, docname: str, typ: str = None) -> str:
return ''
- def get_outdated_docs(self):
- # type: () -> Set[str]
+ def get_outdated_docs(self) -> Set[str]:
return self.env.found_docs
- def prepare_writing(self, docnames):
- # type: (Set[str]) -> None
+ def prepare_writing(self, docnames: Set[str]) -> None:
return
- def compile_catalogs(self, catalogs, message):
- # type: (Set[CatalogInfo], str) -> None
+ def compile_catalogs(self, catalogs: Set[CatalogInfo], message: str) -> None:
return
- def write_doc(self, docname, doctree):
- # type: (str, nodes.document) -> None
+ def write_doc(self, docname: str, doctree: nodes.document) -> None:
catalog = self.catalogs[docname_to_domain(docname, self.config.gettext_compact)]
for toctree in self.env.tocs[docname].traverse(addnodes.toctree):
@@ -176,26 +164,21 @@ if source_date_epoch is not None:
class LocalTimeZone(tzinfo):
-
- def __init__(self, *args, **kw):
- # type: (Any, Any) -> None
+ def __init__(self, *args, **kw) -> None:
super().__init__(*args, **kw) # type: ignore
self.tzdelta = tzdelta
- def utcoffset(self, dt):
- # type: (datetime) -> timedelta
+ def utcoffset(self, dt: datetime) -> timedelta:
return self.tzdelta
- def dst(self, dt):
- # type: (datetime) -> timedelta
+ def dst(self, dt: datetime) -> timedelta:
return timedelta(0)
ltz = LocalTimeZone()
-def should_write(filepath, new_content):
- # type: (str, str) -> bool
+def should_write(filepath: str, new_content: str):
if not path.exists(filepath):
return True
try:
@@ -220,14 +203,12 @@ class MessageCatalogBuilder(I18nBuilder):
name = 'gettext'
epilog = __('The message catalogs are in %(outdir)s.')
- def init(self):
- # type: () -> None
+ def init(self) -> None:
super().init()
self.create_template_bridge()
self.templates.init(self)
- def _collect_templates(self):
- # type: () -> Set[str]
+ def _collect_templates(self) -> Set[str]:
template_files = set()
for template_path in self.config.templates_path:
tmpl_abs_path = path.join(self.app.srcdir, template_path)
@@ -238,8 +219,7 @@ class MessageCatalogBuilder(I18nBuilder):
template_files.add(filename)
return template_files
- def _extract_from_template(self):
- # type: () -> None
+ def _extract_from_template(self) -> None:
files = list(self._collect_templates())
files.sort()
logger.info(bold(__('building [%s]: ') % self.name), nonl=True)
@@ -258,13 +238,11 @@ class MessageCatalogBuilder(I18nBuilder):
except Exception as exc:
raise ThemeError('%s: %r' % (template, exc))
- def build(self, docnames, summary=None, method='update'):
- # type: (Iterable[str], str, str) -> None
+ def build(self, docnames: Iterable[str], summary: str = None, method: str = 'update') -> None: # NOQA
self._extract_from_template()
super().build(docnames, summary, method)
- def finish(self):
- # type: () -> None
+ def finish(self) -> None:
super().finish()
data = {
'version': self.config.version,
@@ -310,8 +288,7 @@ class MessageCatalogBuilder(I18nBuilder):
pofile.write(content)
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
app.add_builder(MessageCatalogBuilder)
app.add_config_value('gettext_compact', True, 'gettext')
diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py
index 81c64d445..f5b8fa0f4 100644
--- a/sphinx/builders/html.py
+++ b/sphinx/builders/html.py
@@ -15,16 +15,21 @@ import sys
import warnings
from hashlib import md5
from os import path
+from typing import Any, Dict, IO, Iterable, Iterator, List, Set, Type, Tuple
from docutils import nodes
from docutils.core import publish_parts
from docutils.frontend import OptionParser
from docutils.io import DocTreeInput, StringOutput
+from docutils.nodes import Node
from docutils.utils import relative_path
from sphinx import package_dir, __display_version__
+from sphinx.application import Sphinx
from sphinx.builders import Builder
+from sphinx.config import Config
from sphinx.deprecation import RemovedInSphinx40Warning
+from sphinx.domains import Domain, Index, IndexEntry
from sphinx.environment.adapters.asset import ImageAdapter
from sphinx.environment.adapters.indexentries import IndexEntries
from sphinx.environment.adapters.toctree import TocTree
@@ -41,16 +46,9 @@ from sphinx.util.i18n import format_date
from sphinx.util.inventory import InventoryFile
from sphinx.util.matching import patmatch, Matcher, DOTFILES
from sphinx.util.osutil import os_path, relative_uri, ensuredir, movefile, copyfile
+from sphinx.util.tags import Tags
from sphinx.writers.html import HTMLWriter, HTMLTranslator
-if False:
- # For type annotation
- from typing import Any, Dict, IO, Iterable, Iterator, List, Set, Type, Tuple # NOQA
- from sphinx.application import Sphinx # NOQA
- from sphinx.config import Config # NOQA
- from sphinx.domains import Domain, Index, IndexEntry # NOQA
- from sphinx.util.tags import Tags # NOQA
-
# HTML5 Writer is avialable or not
if is_html5_writer_available():
from sphinx.writers.html5 import HTML5Translator
@@ -65,8 +63,7 @@ logger = logging.getLogger(__name__)
return_codes_re = re.compile('[\r\n]+')
-def get_stable_hash(obj):
- # type: (Any) -> str
+def get_stable_hash(obj: Any) -> str:
"""
Return a stable hash for a Python data structure. We can't just use
the md5 of str(obj) since for example dictionary items are enumerated
@@ -89,8 +86,7 @@ class Stylesheet(str):
attributes = None # type: Dict[str, str]
filename = None # type: str
- def __new__(cls, filename, *args, **attributes):
- # type: (str, str, str) -> None
+ def __new__(cls, filename: str, *args: str, **attributes: str) -> None:
self = str.__new__(cls, filename) # type: ignore
self.filename = filename
self.attributes = attributes
@@ -113,8 +109,7 @@ class JavaScript(str):
attributes = None # type: Dict[str, str]
filename = None # type: str
- def __new__(cls, filename, **attributes):
- # type: (str, **str) -> None
+ def __new__(cls, filename: str, **attributes: str) -> None:
self = str.__new__(cls, filename) # type: ignore
self.filename = filename
self.attributes = attributes
@@ -131,8 +126,7 @@ class BuildInfo:
"""
@classmethod
- def load(cls, f):
- # type: (IO) -> BuildInfo
+ def load(cls, f: IO) -> "BuildInfo":
try:
lines = f.readlines()
assert lines[0].rstrip() == '# Sphinx build info version 1'
@@ -146,8 +140,7 @@ class BuildInfo:
except Exception as exc:
raise ValueError(__('build info file is broken: %r') % exc)
- def __init__(self, config=None, tags=None, config_categories=[]):
- # type: (Config, Tags, List[str]) -> None
+ def __init__(self, config: Config = None, tags: Tags = None, config_categories: List[str] = []) -> None: # NOQA
self.config_hash = ''
self.tags_hash = ''
@@ -158,13 +151,11 @@ class BuildInfo:
if tags:
self.tags_hash = get_stable_hash(sorted(tags))
- def __eq__(self, other): # type: ignore
- # type: (BuildInfo) -> bool
+ def __eq__(self, other: "BuildInfo") -> bool: # type: ignore
return (self.config_hash == other.config_hash and
self.tags_hash == other.tags_hash)
- def dump(self, f):
- # type: (IO) -> None
+ def dump(self, f: IO) -> None:
f.write('# Sphinx build info version 1\n'
'# This file hashes the configuration used when building these files.'
' When it is not found, a full rebuild will be done.\n'
@@ -204,8 +195,7 @@ class StandaloneHTMLBuilder(Builder):
imgpath = None # type: str
domain_indices = [] # type: List[Tuple[str, Type[Index], List[Tuple[str, List[IndexEntry]]], bool]] # NOQA
- def __init__(self, app):
- # type: (Sphinx) -> None
+ def __init__(self, app: Sphinx) -> None:
super().__init__(app)
# CSS files
@@ -214,8 +204,7 @@ class StandaloneHTMLBuilder(Builder):
# JS files
self.script_files = [] # type: List[JavaScript]
- def init(self):
- # type: () -> None
+ def init(self) -> None:
self.build_info = self.create_build_info()
# basename of images directory
self.imagedir = '_images'
@@ -241,12 +230,10 @@ class StandaloneHTMLBuilder(Builder):
self.use_index = self.get_builder_config('use_index', 'html')
- def create_build_info(self):
- # type: () -> BuildInfo
+ def create_build_info(self) -> BuildInfo:
return BuildInfo(self.config, self.tags, ['html'])
- def _get_translations_js(self):
- # type: () -> str
+ def _get_translations_js(self) -> str:
candidates = [path.join(dir, self.config.language,
'LC_MESSAGES', 'sphinx.js')
for dir in self.config.locale_dirs] + \
@@ -260,12 +247,10 @@ class StandaloneHTMLBuilder(Builder):
return jsfile
return None
- def get_theme_config(self):
- # type: () -> Tuple[str, Dict]
+ def get_theme_config(self) -> Tuple[str, Dict]:
return self.config.html_theme, self.config.html_theme_options
- def init_templates(self):
- # type: () -> None
+ def init_templates(self) -> None:
theme_factory = HTMLThemeFactory(self.app)
themename, themeoptions = self.get_theme_config()
self.theme = theme_factory.create(themename)
@@ -273,8 +258,7 @@ class StandaloneHTMLBuilder(Builder):
self.create_template_bridge()
self.templates.init(self, self.theme)
- def init_highlighter(self):
- # type: () -> None
+ def init_highlighter(self) -> None:
# determine Pygments style and create the highlighter
if self.config.pygments_style is not None:
style = self.config.pygments_style
@@ -284,23 +268,20 @@ class StandaloneHTMLBuilder(Builder):
style = 'sphinx'
self.highlighter = PygmentsBridge('html', style)
- def init_css_files(self):
- # type: () -> None
+ def init_css_files(self) -> None:
for filename, attrs in self.app.registry.css_files:
self.add_css_file(filename, **attrs)
for filename, attrs in self.get_builder_config('css_files', 'html'):
self.add_css_file(filename, **attrs)
- def add_css_file(self, filename, **kwargs):
- # type: (str, **str) -> None
+ def add_css_file(self, filename: str, **kwargs: str) -> None:
if '://' not in filename:
filename = posixpath.join('_static', filename)
self.css_files.append(Stylesheet(filename, **kwargs)) # type: ignore
- def init_js_files(self):
- # type: () -> None
+ def init_js_files(self) -> None:
self.add_js_file('jquery.js')
self.add_js_file('underscore.js')
self.add_js_file('doctools.js')
@@ -315,24 +296,21 @@ class StandaloneHTMLBuilder(Builder):
if self.config.language and self._get_translations_js():
self.add_js_file('translations.js')
- def add_js_file(self, filename, **kwargs):
- # type: (str, **str) -> None
+ def add_js_file(self, filename: str, **kwargs: str) -> None:
if filename and '://' not in filename:
filename = posixpath.join('_static', filename)
self.script_files.append(JavaScript(filename, **kwargs))
@property
- def default_translator_class(self): # type: ignore
- # type: () -> Type[nodes.NodeVisitor]
+ def default_translator_class(self) -> Type[nodes.NodeVisitor]: # type: ignore
if not html5_ready or self.config.html4_writer:
return HTMLTranslator
else:
return HTML5Translator
@property
- def math_renderer_name(self):
- # type: () -> str
+ def math_renderer_name(self) -> str:
name = self.get_builder_config('math_renderer', 'html')
if name is not None:
# use given name
@@ -351,8 +329,7 @@ class StandaloneHTMLBuilder(Builder):
# many math_renderers are registered. can't choose automatically!
return None
- def get_outdated_docs(self):
- # type: () -> Iterator[str]
+ def get_outdated_docs(self) -> Iterator[str]:
try:
with open(path.join(self.outdir, '.buildinfo')) as fp:
buildinfo = BuildInfo.load(fp)
@@ -388,12 +365,10 @@ class StandaloneHTMLBuilder(Builder):
# source doesn't exist anymore
pass
- def get_asset_paths(self):
- # type: () -> List[str]
+ def get_asset_paths(self) -> List[str]:
return self.config.html_extra_path + self.config.html_static_path
- def render_partial(self, node):
- # type: (nodes.Node) -> Dict[str, str]
+ def render_partial(self, node: Node) -> Dict[str, str]:
"""Utility: Render a lone doctree node."""
if node is None:
return {'fragment': ''}
@@ -407,8 +382,7 @@ class StandaloneHTMLBuilder(Builder):
settings_overrides={'output_encoding': 'unicode'},
source=doc)
- def prepare_writing(self, docnames):
- # type: (Set[str]) -> None
+ def prepare_writing(self, docnames: Set[str]) -> None:
# create the search indexer
self.indexer = None
if self.search:
@@ -517,8 +491,7 @@ class StandaloneHTMLBuilder(Builder):
self.theme.get_options(self.theme_options).items())
self.globalcontext.update(self.config.html_context)
- def get_doc_context(self, docname, body, metatags):
- # type: (str, str, str) -> Dict[str, Any]
+ def get_doc_context(self, docname: str, body: str, metatags: str) -> Dict[str, Any]:
"""Collect items for the template context of a page."""
# find out relations
prev = next = None
@@ -598,8 +571,7 @@ class StandaloneHTMLBuilder(Builder):
'page_source_suffix': source_suffix,
}
- def write_doc(self, docname, doctree):
- # type: (str, nodes.document) -> None
+ def write_doc(self, docname: str, doctree: nodes.document) -> None:
destination = StringOutput(encoding='utf-8')
doctree.settings = self.docsettings
@@ -616,16 +588,14 @@ class StandaloneHTMLBuilder(Builder):
ctx = self.get_doc_context(docname, body, metatags)
self.handle_page(docname, ctx, event_arg=doctree)
- def write_doc_serialized(self, docname, doctree):
- # type: (str, nodes.document) -> None
+ def write_doc_serialized(self, docname: str, doctree: nodes.document) -> None:
self.imgpath = relative_uri(self.get_target_uri(docname), self.imagedir)
self.post_process_images(doctree)
title_node = self.env.longtitles.get(docname)
title = title_node and self.render_partial(title_node)['title'] or ''
self.index_page(docname, doctree, title)
- def finish(self):
- # type: () -> None
+ def finish(self) -> None:
self.finish_tasks.add_task(self.gen_indices)
self.finish_tasks.add_task(self.gen_additional_pages)
self.finish_tasks.add_task(self.copy_image_files)
@@ -637,8 +607,7 @@ class StandaloneHTMLBuilder(Builder):
# dump the search index
self.handle_finish()
- def gen_indices(self):
- # type: () -> None
+ def gen_indices(self) -> None:
logger.info(bold(__('generating indices...')), nonl=True)
# the global general index
@@ -650,8 +619,7 @@ class StandaloneHTMLBuilder(Builder):
logger.info('')
- def gen_additional_pages(self):
- # type: () -> None
+ def gen_additional_pages(self) -> None:
# pages from extensions
for pagelist in self.events.emit('html-collect-pages'):
for pagename, context, template in pagelist:
@@ -677,8 +645,7 @@ class StandaloneHTMLBuilder(Builder):
logger.info('')
- def write_genindex(self):
- # type: () -> None
+ def write_genindex(self) -> None:
# the total count of lines for each index letter, used to distribute
# the entries into two columns
genindex = IndexEntries(self.env).create_index(self)
@@ -707,8 +674,7 @@ class StandaloneHTMLBuilder(Builder):
else:
self.handle_page('genindex', genindexcontext, 'genindex.html')
- def write_domain_indices(self):
- # type: () -> None
+ def write_domain_indices(self) -> None:
for indexname, indexcls, content, collapse in self.domain_indices:
indexcontext = {
'indextitle': indexcls.localname,
@@ -718,8 +684,7 @@ class StandaloneHTMLBuilder(Builder):
logger.info(' ' + indexname, nonl=True)
self.handle_page(indexname, indexcontext, 'domainindex.html')
- def copy_image_files(self):
- # type: () -> None
+ def copy_image_files(self) -> None:
if self.images:
stringify_func = ImageAdapter(self.app.env).get_original_image_uri
ensuredir(path.join(self.outdir, self.imagedir))
@@ -734,11 +699,10 @@ class StandaloneHTMLBuilder(Builder):
logger.warning(__('cannot copy image file %r: %s'),
path.join(self.srcdir, src), err)
- def copy_download_files(self):
- # type: () -> None
- def to_relpath(f):
- # type: (str) -> str
+ def copy_download_files(self) -> None:
+ def to_relpath(f: str) -> str:
return relative_path(self.srcdir, f)
+
# copy downloadable files
if self.env.dlfiles:
ensuredir(path.join(self.outdir, '_downloads'))
@@ -753,8 +717,7 @@ class StandaloneHTMLBuilder(Builder):
logger.warning(__('cannot copy downloadable file %r: %s'),
path.join(self.srcdir, src), err)
- def copy_static_files(self):
- # type: () -> None
+ def copy_static_files(self) -> None:
try:
# copy static files
logger.info(bold(__('copying static files... ')), nonl=True)
@@ -818,8 +781,7 @@ class StandaloneHTMLBuilder(Builder):
except OSError as err:
logger.warning(__('cannot copy static file %r'), err)
- def copy_extra_files(self):
- # type: () -> None
+ def copy_extra_files(self) -> None:
try:
# copy html_extra_path files
logger.info(bold(__('copying extra files... ')), nonl=True)
@@ -836,22 +798,19 @@ class StandaloneHTMLBuilder(Builder):
except OSError as err:
logger.warning(__('cannot copy extra file %r'), err)
- def write_buildinfo(self):
- # type: () -> None
+ def write_buildinfo(self) -> None:
try:
with open(path.join(self.outdir, '.buildinfo'), 'w') as fp:
self.build_info.dump(fp)
except OSError as exc:
logger.warning(__('Failed to write build info file: %r'), exc)
- def cleanup(self):
- # type: () -> None
+ def cleanup(self) -> None:
# clean up theme stuff
if self.theme:
self.theme.cleanup()
- def post_process_images(self, doctree):
- # type: (nodes.Node) -> None
+ def post_process_images(self, doctree: Node) -> None:
"""Pick the best candidate for an image and link down-scaled images to
their high res version.
"""
@@ -876,8 +835,7 @@ class StandaloneHTMLBuilder(Builder):
node.replace_self(reference)
reference.append(node)
- def load_indexer(self, docnames):
- # type: (Iterable[str]) -> None
+ def load_indexer(self, docnames: Iterable[str]) -> None:
keep = set(self.env.all_docs) - set(docnames)
try:
searchindexfn = path.join(self.outdir, self.searchindex_filename)
@@ -895,8 +853,7 @@ class StandaloneHTMLBuilder(Builder):
# delete all entries for files that will be rebuilt
self.indexer.prune(keep)
- def index_page(self, pagename, doctree, title):
- # type: (str, nodes.document, str) -> None
+ def index_page(self, pagename: str, doctree: nodes.document, title: str) -> None:
# only index pages with title
if self.indexer is not None and title:
filename = self.env.doc2path(pagename, base=None)
@@ -912,22 +869,19 @@ class StandaloneHTMLBuilder(Builder):
indexer_name, indexer_name),
RemovedInSphinx40Warning)
- def _get_local_toctree(self, docname, collapse=True, **kwds):
- # type: (str, bool, Any) -> str
+ def _get_local_toctree(self, docname: str, collapse: bool = True, **kwds) -> str:
if 'includehidden' not in kwds:
kwds['includehidden'] = False
return self.render_partial(TocTree(self.env).get_toctree_for(
docname, self, collapse, **kwds))['fragment']
- def get_outfilename(self, pagename):
- # type: (str) -> str
+ def get_outfilename(self, pagename: str) -> str:
return path.join(self.outdir, os_path(pagename) + self.out_suffix)
- def add_sidebars(self, pagename, ctx):
- # type: (str, Dict) -> None
- def has_wildcard(pattern):
- # type: (str) -> bool
+ def add_sidebars(self, pagename: str, ctx: Dict) -> None:
+ def has_wildcard(pattern: str) -> bool:
return any(char in pattern for char in '*?[')
+
sidebars = None
matched = None
customsidebar = None
@@ -976,13 +930,11 @@ class StandaloneHTMLBuilder(Builder):
# --------- these are overwritten by the serialization builder
- def get_target_uri(self, docname, typ=None):
- # type: (str, str) -> str
+ def get_target_uri(self, docname: str, typ: str = None) -> str:
return docname + self.link_suffix
- def handle_page(self, pagename, addctx, templatename='page.html',
- outfilename=None, event_arg=None):
- # type: (str, Dict, str, str, Any) -> None
+ def handle_page(self, pagename: str, addctx: Dict, templatename: str = 'page.html',
+ outfilename: str = None, event_arg: Any = None) -> None:
ctx = self.globalcontext.copy()
# current_page_name is backwards compatibility
ctx['pagename'] = ctx['current_page_name'] = pagename
@@ -998,8 +950,7 @@ class StandaloneHTMLBuilder(Builder):
else:
ctx['pageurl'] = None
- def pathto(otheruri, resource=False, baseuri=default_baseuri):
- # type: (str, bool, str) -> str
+ def pathto(otheruri: str, resource: bool = False, baseuri: str = default_baseuri) -> str: # NOQA
if resource and '://' in otheruri:
# allow non-local resources given by scheme
return otheruri
@@ -1011,8 +962,7 @@ class StandaloneHTMLBuilder(Builder):
return uri
ctx['pathto'] = pathto
- def css_tag(css):
- # type: (Stylesheet) -> str
+ def css_tag(css: Stylesheet) -> str:
attrs = []
for key in sorted(css.attributes):
value = css.attributes[key]
@@ -1022,8 +972,7 @@ class StandaloneHTMLBuilder(Builder):
return '<link %s />' % ' '.join(attrs)
ctx['css_tag'] = css_tag
- def hasdoc(name):
- # type: (str) -> bool
+ def hasdoc(name: str) -> bool:
if name in self.env.all_docs:
return True
elif name == 'search' and self.search:
@@ -1071,24 +1020,21 @@ class StandaloneHTMLBuilder(Builder):
ensuredir(path.dirname(source_name))
copyfile(self.env.doc2path(pagename), source_name)
- def update_page_context(self, pagename, templatename, ctx, event_arg):
- # type: (str, str, Dict, Any) -> None
+ def update_page_context(self, pagename: str, templatename: str,
+ ctx: Dict, event_arg: Any) -> None:
pass
- def handle_finish(self):
- # type: () -> None
+ def handle_finish(self) -> None:
if self.indexer:
self.finish_tasks.add_task(self.dump_search_index)
self.finish_tasks.add_task(self.dump_inventory)
- def dump_inventory(self):
- # type: () -> None
+ def dump_inventory(self) -> None:
logger.info(bold(__('dumping object inventory... ')), nonl=True)
InventoryFile.dump(path.join(self.outdir, INVENTORY_FILENAME), self.env, self)
logger.info(__('done'))
- def dump_search_index(self):
- # type: () -> None
+ def dump_search_index(self) -> None:
logger.info(
bold(__('dumping search index in %s ... ') % self.indexer.label()),
nonl=True)
@@ -1106,8 +1052,7 @@ class StandaloneHTMLBuilder(Builder):
logger.info(__('done'))
-def convert_html_css_files(app, config):
- # type: (Sphinx, Config) -> None
+def convert_html_css_files(app: Sphinx, config: Config) -> None:
"""This converts string styled html_css_files to tuple styled one."""
html_css_files = [] # type: List[Tuple[str, Dict]]
for entry in config.html_css_files:
@@ -1124,8 +1069,7 @@ def convert_html_css_files(app, config):
config.html_css_files = html_css_files # type: ignore
-def convert_html_js_files(app, config):
- # type: (Sphinx, Config) -> None
+def convert_html_js_files(app: Sphinx, config: Config) -> None:
"""This converts string styled html_js_files to tuple styled one."""
html_js_files = [] # type: List[Tuple[str, Dict]]
for entry in config.html_js_files:
@@ -1142,16 +1086,15 @@ def convert_html_js_files(app, config):
config.html_js_files = html_js_files # type: ignore
-def setup_js_tag_helper(app, pagename, templatexname, context, doctree):
- # type: (Sphinx, str, str, Dict, nodes.Node) -> None
+def setup_js_tag_helper(app: Sphinx, pagename: str, templatexname: str,
+ context: Dict, doctree: Node) -> None:
"""Set up js_tag() template helper.
.. note:: This set up function is added to keep compatibility with webhelper.
"""
pathto = context.get('pathto')
- def js_tag(js):
- # type: (JavaScript) -> str
+ def js_tag(js: JavaScript) -> str:
attrs = []
body = ''
if isinstance(js, JavaScript):
@@ -1173,8 +1116,7 @@ def setup_js_tag_helper(app, pagename, templatexname, context, doctree):
context['js_tag'] = js_tag
-def validate_math_renderer(app):
- # type: (Sphinx) -> None
+def validate_math_renderer(app: Sphinx) -> None:
if app.builder.format != 'html':
return
@@ -1192,8 +1134,7 @@ import sphinx.builders.singlehtml # NOQA
import sphinxcontrib.serializinghtml # NOQA
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
# builders
app.add_builder(StandaloneHTMLBuilder)
diff --git a/sphinx/builders/htmlhelp.py b/sphinx/builders/htmlhelp.py
index be365ef7e..7885acd08 100644
--- a/sphinx/builders/htmlhelp.py
+++ b/sphinx/builders/htmlhelp.py
@@ -10,20 +10,16 @@
"""
import warnings
+from typing import Any, Dict
from sphinxcontrib.htmlhelp import (
chm_locales, chm_htmlescape, HTMLHelpBuilder, default_htmlhelp_basename
)
+from sphinx.application import Sphinx
from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
-if False:
- # For type annotation
- from typing import Any, Dict # NOQA
- from sphinx.application import Sphinx # NOQA
-
-
deprecated_alias('sphinx.builders.htmlhelp',
{
'chm_locales': chm_locales,
@@ -34,8 +30,7 @@ deprecated_alias('sphinx.builders.htmlhelp',
RemovedInSphinx40Warning)
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
warnings.warn('sphinx.builders.htmlhelp has been moved to sphinxcontrib-htmlhelp.',
RemovedInSphinx40Warning)
app.setup_extension('sphinxcontrib.htmlhelp')
diff --git a/sphinx/builders/latex/__init__.py b/sphinx/builders/latex/__init__.py
index e5754ec9b..69735ec47 100644
--- a/sphinx/builders/latex/__init__.py
+++ b/sphinx/builders/latex/__init__.py
@@ -11,14 +11,17 @@
import os
import warnings
from os import path
+from typing import Any, Dict, Iterable, List, Tuple, Union
from docutils.frontend import OptionParser
+from docutils.nodes import Node
import sphinx.builders.latex.nodes # NOQA # Workaround: import this before writer to avoid ImportError
from sphinx import package_dir, addnodes, highlighting
+from sphinx.application import Sphinx
from sphinx.builders import Builder
from sphinx.builders.latex.util import ExtBabel
-from sphinx.config import ENUM
+from sphinx.config import Config, ENUM
from sphinx.deprecation import RemovedInSphinx40Warning
from sphinx.environment.adapters.asset import ImageAdapter
from sphinx.errors import NoUri, SphinxError
@@ -38,12 +41,6 @@ from sphinx.writers.latex import (
# load docutils.nodes after loading sphinx.builders.latex.nodes
from docutils import nodes # NOQA
-if False:
- # For type annotation
- from typing import Any, Dict, Iterable, List, Tuple, Union # NOQA
- from sphinx.application import Sphinx # NOQA
- from sphinx.config import Config # NOQA
-
XINDY_LANG_OPTIONS = {
# language codes from docutils.writers.latex2e.Babel
@@ -125,8 +122,7 @@ class LaTeXBuilder(Builder):
supported_remote_images = False
default_translator_class = LaTeXTranslator
- def init(self):
- # type: () -> None
+ def init(self) -> None:
self.babel = None # type: ExtBabel
self.context = {} # type: Dict[str, Any]
self.docnames = [] # type: Iterable[str]
@@ -137,24 +133,20 @@ class LaTeXBuilder(Builder):
self.init_context()
self.init_babel()
- def get_outdated_docs(self):
- # type: () -> Union[str, List[str]]
+ def get_outdated_docs(self) -> Union[str, List[str]]:
return 'all documents' # for now
- def get_target_uri(self, docname, typ=None):
- # type: (str, str) -> str
+ def get_target_uri(self, docname: str, typ: str = None) -> str:
if docname not in self.docnames:
raise NoUri
else:
return '%' + docname
- def get_relative_uri(self, from_, to, typ=None):
- # type: (str, str, str) -> str
+ def get_relative_uri(self, from_: str, to: str, typ: str = None) -> str:
# ignore source path
return self.get_target_uri(to, typ)
- def init_document_data(self):
- # type: () -> None
+ def init_document_data(self) -> None:
preliminary_document_data = [list(x) for x in self.config.latex_documents]
if not preliminary_document_data:
logger.warning(__('no "latex_documents" config value found; no documents '
@@ -173,8 +165,7 @@ class LaTeXBuilder(Builder):
docname = docname[:-5]
self.titles.append((docname, entry[2]))
- def init_context(self):
- # type: () -> None
+ def init_context(self) -> None:
self.context = DEFAULT_SETTINGS.copy()
# Add special settings for latex_engine
@@ -208,8 +199,7 @@ class LaTeXBuilder(Builder):
# Show the release label only if release value exists
self.context.setdefault('releasename', _('Release'))
- def init_babel(self):
- # type: () -> None
+ def init_babel(self) -> None:
self.babel = ExtBabel(self.config.language, not self.context['babel'])
if self.config.language and not self.babel.is_supported_language():
# emit warning if specified language is invalid
@@ -217,8 +207,7 @@ class LaTeXBuilder(Builder):
logger.warning(__('no Babel option known for language %r'),
self.config.language)
- def write_stylesheet(self):
- # type: () -> None
+ def write_stylesheet(self) -> None:
highlighter = highlighting.PygmentsBridge('latex', self.config.pygments_style)
stylesheet = path.join(self.outdir, 'sphinxhighlight.sty')
with open(stylesheet, 'w') as f:
@@ -227,8 +216,7 @@ class LaTeXBuilder(Builder):
'[2016/05/29 stylesheet for highlighting with pygments]\n\n')
f.write(highlighter.get_stylesheet())
- def write(self, *ignored):
- # type: (Any) -> None
+ def write(self, *ignored) -> None:
docwriter = LaTeXWriter(self)
docsettings = OptionParser(
defaults=self.env.settings,
@@ -271,8 +259,7 @@ class LaTeXBuilder(Builder):
doctree.settings = docsettings
docwriter.write(doctree, destination)
- def get_contentsname(self, indexfile):
- # type: (str) -> str
+ def get_contentsname(self, indexfile: str) -> str:
tree = self.env.get_doctree(indexfile)
contentsname = None
for toctree in tree.traverse(addnodes.toctree):
@@ -282,13 +269,11 @@ class LaTeXBuilder(Builder):
return contentsname
- def update_doc_context(self, title, author):
- # type: (str, str) -> None
+ def update_doc_context(self, title: str, author: str) -> None:
self.context['title'] = title
self.context['author'] = author
- def assemble_doctree(self, indexfile, toctree_only, appendices):
- # type: (str, bool, List[str]) -> nodes.document
+ def assemble_doctree(self, indexfile: str, toctree_only: bool, appendices: List[str]) -> nodes.document: # NOQA
self.docnames = set([indexfile] + appendices)
logger.info(darkgreen(indexfile) + " ", nonl=True)
tree = self.env.get_doctree(indexfile)
@@ -319,7 +304,7 @@ class LaTeXBuilder(Builder):
for pendingnode in largetree.traverse(addnodes.pending_xref):
docname = pendingnode['refdocname']
sectname = pendingnode['refsectname']
- newnodes = [nodes.emphasis(sectname, sectname)] # type: List[nodes.Node]
+ newnodes = [nodes.emphasis(sectname, sectname)] # type: List[Node]
for subdir, title in self.titles:
if docname.startswith(subdir):
newnodes.append(nodes.Text(_(' (in '), _(' (in ')))
@@ -331,13 +316,11 @@ class LaTeXBuilder(Builder):
pendingnode.replace_self(newnodes)
return largetree
- def apply_transforms(self, doctree):
- # type: (nodes.document) -> None
+ def apply_transforms(self, doctree: nodes.document) -> None:
warnings.warn('LaTeXBuilder.apply_transforms() is deprecated.',
RemovedInSphinx40Warning)
- def finish(self):
- # type: () -> None
+ def finish(self) -> None:
self.copy_image_files()
self.write_message_catalog()
self.copy_support_files()
@@ -346,8 +329,7 @@ class LaTeXBuilder(Builder):
self.copy_latex_additional_files()
@progress_message(__('copying TeX support files'))
- def copy_support_files(self):
- # type: () -> None
+ def copy_support_files(self) -> None:
"""copy TeX support files from texinputs."""
# configure usage of xindy (impacts Makefile and latexmkrc)
# FIXME: convert this rather to a confval with suitable default
@@ -387,14 +369,12 @@ class LaTeXBuilder(Builder):
copy_asset_file(path.join(self.confdir, self.config.latex_logo), self.outdir)
@progress_message(__('copying additional files'))
- def copy_latex_additional_files(self):
- # type: () -> None
+ def copy_latex_additional_files(self) -> None:
for filename in self.config.latex_additional_files:
logger.info(' ' + filename, nonl=True)
copy_asset_file(path.join(self.confdir, filename), self.outdir)
- def copy_image_files(self):
- # type: () -> None
+ def copy_image_files(self) -> None:
if self.images:
stringify_func = ImageAdapter(self.app.env).get_original_image_uri
for src in status_iterator(self.images, __('copying images... '), "brown",
@@ -408,8 +388,7 @@ class LaTeXBuilder(Builder):
logger.warning(__('cannot copy image file %r: %s'),
path.join(self.srcdir, src), err)
- def write_message_catalog(self):
- # type: () -> None
+ def write_message_catalog(self) -> None:
formats = self.config.numfig_format
context = {
'addtocaptions': r'\@iden',
@@ -425,8 +404,7 @@ class LaTeXBuilder(Builder):
copy_asset_file(filename, self.outdir, context=context, renderer=LaTeXRenderer())
-def validate_config_values(app, config):
- # type: (Sphinx, Config) -> None
+def validate_config_values(app: Sphinx, config: Config) -> None:
for key in list(config.latex_elements):
if key not in DEFAULT_SETTINGS:
msg = __("Unknown configure key: latex_elements[%r]. ignored.")
@@ -434,8 +412,7 @@ def validate_config_values(app, config):
config.latex_elements.pop(key)
-def default_latex_engine(config):
- # type: (Config) -> str
+def default_latex_engine(config: Config) -> str:
""" Better default latex_engine settings for specific languages. """
if config.language == 'ja':
return 'platex'
@@ -445,8 +422,7 @@ def default_latex_engine(config):
return 'pdflatex'
-def default_latex_docclass(config):
- # type: (Config) -> Dict[str, str]
+def default_latex_docclass(config: Config) -> Dict[str, str]:
""" Better default latex_docclass settings for specific languages. """
if config.language == 'ja':
return {'manual': 'jsbook',
@@ -455,14 +431,12 @@ def default_latex_docclass(config):
return {}
-def default_latex_use_xindy(config):
- # type: (Config) -> bool
+def default_latex_use_xindy(config: Config) -> bool:
""" Better default latex_use_xindy settings for specific engines. """
return config.latex_engine in {'xelatex', 'lualatex'}
-def default_latex_documents(config):
- # type: (Config) -> List[Tuple[str, str, str, str, str]]
+def default_latex_documents(config: Config) -> List[Tuple[str, str, str, str, str]]:
""" Better default latex_documents settings. """
return [(config.master_doc,
make_filename_from_project(config.project) + '.tex',
@@ -471,8 +445,7 @@ def default_latex_documents(config):
'manual')]
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
app.setup_extension('sphinx.builders.latex.transforms')
app.add_builder(LaTeXBuilder)
diff --git a/sphinx/builders/latex/transforms.py b/sphinx/builders/latex/transforms.py
index 6381780ae..9fe44bc95 100644
--- a/sphinx/builders/latex/transforms.py
+++ b/sphinx/builders/latex/transforms.py
@@ -8,11 +8,14 @@
:license: BSD, see LICENSE for details.
"""
+from typing import Any, Dict, List, Set, Tuple
from typing import cast
from docutils import nodes
+from docutils.nodes import Element, Node
from sphinx import addnodes
+from sphinx.application import Sphinx
from sphinx.builders.latex.nodes import (
captioned_literal_block, footnotemark, footnotetext, math_reference, thebibliography
)
@@ -21,11 +24,6 @@ from sphinx.transforms import SphinxTransform
from sphinx.transforms.post_transforms import SphinxPostTransform
from sphinx.util.nodes import NodeMatcher
-if False:
- # For type annotation
- from typing import Any, Dict, List, Set, Tuple # NOQA
- from sphinx.application import Sphinx # NOQA
-
URI_SCHEMES = ('mailto:', 'http:', 'https:', 'ftp:')
@@ -34,8 +32,7 @@ class FootnoteDocnameUpdater(SphinxTransform):
default_priority = 700
TARGET_NODES = (nodes.footnote, nodes.footnote_reference)
- def apply(self, **kwargs):
- # type: (Any) -> None
+ def apply(self, **kwargs) -> None:
matcher = NodeMatcher(*self.TARGET_NODES)
for node in self.document.traverse(matcher): # type: nodes.Element
node['docname'] = self.env.docname
@@ -54,8 +51,7 @@ class ShowUrlsTransform(SphinxPostTransform):
# references are expanded to footnotes (or not)
expanded = False
- def run(self, **kwargs):
- # type: (Any) -> None
+ def run(self, **kwargs) -> None:
try:
# replace id_prefix temporarily
settings = self.document.settings # type: Any
@@ -69,8 +65,7 @@ class ShowUrlsTransform(SphinxPostTransform):
# restore id_prefix
settings.id_prefix = id_prefix
- def expand_show_urls(self):
- # type: () -> None
+ def expand_show_urls(self) -> None:
show_urls = self.config.latex_show_urls
if show_urls is False or show_urls == 'no':
return
@@ -93,8 +88,7 @@ class ShowUrlsTransform(SphinxPostTransform):
textnode = nodes.Text(" (%s)" % uri)
node.parent.insert(index + 1, textnode)
- def get_docname_for_node(self, node):
- # type: (nodes.Node) -> str
+ def get_docname_for_node(self, node: Node) -> str:
while node:
if isinstance(node, nodes.document):
return self.env.path2doc(node['source'])
@@ -105,8 +99,7 @@ class ShowUrlsTransform(SphinxPostTransform):
return None # never reached here. only for type hinting
- def create_footnote(self, uri, docname):
- # type: (str, str) -> Tuple[nodes.footnote, nodes.footnote_reference]
+ def create_footnote(self, uri: str, docname: str) -> Tuple[nodes.footnote, nodes.footnote_reference]: # NOQA
reference = nodes.reference('', nodes.Text(uri), refuri=uri, nolinkurl=True)
footnote = nodes.footnote(uri, auto=1, docname=docname)
footnote['names'].append('#')
@@ -122,8 +115,7 @@ class ShowUrlsTransform(SphinxPostTransform):
return footnote, footnote_ref
- def renumber_footnotes(self):
- # type: () -> None
+ def renumber_footnotes(self) -> None:
collector = FootnoteCollector(self.document)
self.document.walkabout(collector)
@@ -153,31 +145,26 @@ class ShowUrlsTransform(SphinxPostTransform):
class FootnoteCollector(nodes.NodeVisitor):
"""Collect footnotes and footnote references on the document"""
- def __init__(self, document):
- # type: (nodes.document) -> None
+ def __init__(self, document: nodes.document) -> None:
self.auto_footnotes = [] # type: List[nodes.footnote]
self.used_footnote_numbers = set() # type: Set[str]
self.footnote_refs = [] # type: List[nodes.footnote_reference]
super().__init__(document)
- def unknown_visit(self, node):
- # type: (nodes.Node) -> None
+ def unknown_visit(self, node: Node) -> None:
pass
- def unknown_departure(self, node):
- # type: (nodes.Node) -> None
+ def unknown_departure(self, node: Node) -> None:
pass
- def visit_footnote(self, node):
- # type: (nodes.footnote) -> None
+ def visit_footnote(self, node: nodes.footnote) -> None:
if node.get('auto'):
self.auto_footnotes.append(node)
else:
for name in node['names']:
self.used_footnote_numbers.add(name)
- def visit_footnote_reference(self, node):
- # type: (nodes.footnote_reference) -> None
+ def visit_footnote_reference(self, node: nodes.footnote_reference) -> None:
self.footnote_refs.append(node)
@@ -351,8 +338,7 @@ class LaTeXFootnoteTransform(SphinxPostTransform):
default_priority = 600
builders = ('latex',)
- def run(self, **kwargs):
- # type: (Any) -> None
+ def run(self, **kwargs) -> None:
footnotes = list(self.document.traverse(nodes.footnote))
for node in footnotes:
node.parent.remove(node)
@@ -362,8 +348,7 @@ class LaTeXFootnoteTransform(SphinxPostTransform):
class LaTeXFootnoteVisitor(nodes.NodeVisitor):
- def __init__(self, document, footnotes):
- # type: (nodes.document, List[nodes.footnote]) -> None
+ def __init__(self, document: nodes.document, footnotes: List[nodes.footnote]) -> None:
self.appeared = set() # type: Set[Tuple[str, str]]
self.footnotes = footnotes # type: List[nodes.footnote]
self.pendings = [] # type: List[nodes.footnote]
@@ -371,21 +356,17 @@ class LaTeXFootnoteVisitor(nodes.NodeVisitor):
self.restricted = None # type: nodes.Element
super().__init__(document)
- def unknown_visit(self, node):
- # type: (nodes.Node) -> None
+ def unknown_visit(self, node: Node) -> None:
pass
- def unknown_departure(self, node):
- # type: (nodes.Node) -> None
+ def unknown_departure(self, node: Node) -> None:
pass
- def restrict(self, node):
- # type: (nodes.Element) -> None
+ def restrict(self, node: Element) -> None:
if self.restricted is None:
self.restricted = node
- def unrestrict(self, node):
- # type: (nodes.Element) -> None
+ def unrestrict(self, node: Element) -> None:
if self.restricted == node:
self.restricted = None
pos = node.parent.index(node)
@@ -394,37 +375,29 @@ class LaTeXFootnoteVisitor(nodes.NodeVisitor):
node.parent.insert(pos + i + 1, fntext)
self.pendings = []
- def visit_figure(self, node):
- # type: (nodes.figure) -> None
+ def visit_figure(self, node: nodes.figure) -> None:
self.restrict(node)
- def depart_figure(self, node):
- # type: (nodes.figure) -> None
+ def depart_figure(self, node: nodes.figure) -> None:
self.unrestrict(node)
- def visit_term(self, node):
- # type: (nodes.term) -> None
+ def visit_term(self, node: nodes.term) -> None:
self.restrict(node)
- def depart_term(self, node):
- # type: (nodes.term) -> None
+ def depart_term(self, node: nodes.term) -> None:
self.unrestrict(node)
- def visit_caption(self, node):
- # type: (nodes.caption) -> None
+ def visit_caption(self, node: nodes.caption) -> None:
self.restrict(node)
- def depart_caption(self, node):
- # type: (nodes.caption) -> None
+ def depart_caption(self, node: nodes.caption) -> None:
self.unrestrict(node)
- def visit_title(self, node):
- # type: (nodes.title) -> None
+ def visit_title(self, node: nodes.title) -> None:
if isinstance(node.parent, (nodes.section, nodes.table)):
self.restrict(node)
- def depart_title(self, node):
- # type: (nodes.title) -> None
+ def depart_title(self, node: nodes.title) -> None:
if isinstance(node.parent, nodes.section):
self.unrestrict(node)
elif isinstance(node.parent, nodes.table):
@@ -432,18 +405,15 @@ class LaTeXFootnoteVisitor(nodes.NodeVisitor):
self.pendings = []
self.unrestrict(node)
- def visit_thead(self, node):
- # type: (nodes.thead) -> None
+ def visit_thead(self, node: nodes.thead) -> None:
self.restrict(node)
- def depart_thead(self, node):
- # type: (nodes.thead) -> None
+ def depart_thead(self, node: nodes.thead) -> None:
self.table_footnotes += self.pendings
self.pendings = []
self.unrestrict(node)
- def depart_table(self, node):
- # type: (nodes.table) -> None
+ def depart_table(self, node: nodes.table) -> None:
tbody = list(node.traverse(nodes.tbody))[0]
for footnote in reversed(self.table_footnotes):
fntext = footnotetext('', *footnote.children)
@@ -451,16 +421,13 @@ class LaTeXFootnoteVisitor(nodes.NodeVisitor):
self.table_footnotes = []
- def visit_footnote(self, node):
- # type: (nodes.footnote) -> None
+ def visit_footnote(self, node: nodes.footnote) -> None:
self.restrict(node)
- def depart_footnote(self, node):
- # type: (nodes.footnote) -> None
+ def depart_footnote(self, node: nodes.footnote) -> None:
self.unrestrict(node)
- def visit_footnote_reference(self, node):
- # type: (nodes.footnote_reference) -> None
+ def visit_footnote_reference(self, node: nodes.footnote_reference) -> None:
number = node.astext().strip()
docname = node['docname']
if self.restricted:
@@ -481,8 +448,7 @@ class LaTeXFootnoteVisitor(nodes.NodeVisitor):
self.appeared.add((docname, number))
raise nodes.SkipNode
- def get_footnote_by_reference(self, node):
- # type: (nodes.footnote_reference) -> nodes.footnote
+ def get_footnote_by_reference(self, node: nodes.footnote_reference) -> nodes.footnote:
docname = node['docname']
for footnote in self.footnotes:
if docname == footnote['docname'] and footnote['ids'][0] == node['refid']:
@@ -524,8 +490,7 @@ class BibliographyTransform(SphinxPostTransform):
default_priority = 750
builders = ('latex',)
- def run(self, **kwargs):
- # type: (Any) -> None
+ def run(self, **kwargs) -> None:
citations = thebibliography()
for node in self.document.traverse(nodes.citation):
node.parent.remove(node)
@@ -544,8 +509,7 @@ class CitationReferenceTransform(SphinxPostTransform):
default_priority = 5 # before ReferencesResolver
builders = ('latex',)
- def run(self, **kwargs):
- # type: (Any) -> None
+ def run(self, **kwargs) -> None:
domain = cast(CitationDomain, self.env.get_domain('citation'))
matcher = NodeMatcher(addnodes.pending_xref, refdomain='citation', reftype='ref')
for node in self.document.traverse(matcher): # type: addnodes.pending_xref
@@ -565,8 +529,7 @@ class MathReferenceTransform(SphinxPostTransform):
default_priority = 5 # before ReferencesResolver
builders = ('latex',)
- def run(self, **kwargs):
- # type: (Any) -> None
+ def run(self, **kwargs) -> None:
equations = self.env.get_domain('math').data['objects']
for node in self.document.traverse(addnodes.pending_xref):
if node['refdomain'] == 'math' and node['reftype'] in ('eq', 'numref'):
@@ -581,8 +544,7 @@ class LiteralBlockTransform(SphinxPostTransform):
default_priority = 400
builders = ('latex',)
- def run(self, **kwargs):
- # type: (Any) -> None
+ def run(self, **kwargs) -> None:
matcher = NodeMatcher(nodes.container, literal_block=True)
for node in self.document.traverse(matcher): # type: nodes.container
newnode = captioned_literal_block('', *node.children, **node.attributes)
@@ -594,8 +556,7 @@ class DocumentTargetTransform(SphinxPostTransform):
default_priority = 400
builders = ('latex',)
- def run(self, **kwargs):
- # type: (Any) -> None
+ def run(self, **kwargs) -> None:
for node in self.document.traverse(addnodes.start_of_file):
section = node.next_node(nodes.section)
if section:
@@ -639,8 +600,7 @@ class IndexInSectionTitleTransform(SphinxTransform):
node.parent.insert(i + 1, index)
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
app.add_transform(FootnoteDocnameUpdater)
app.add_post_transform(BibliographyTransform)
app.add_post_transform(CitationReferenceTransform)
diff --git a/sphinx/builders/latex/util.py b/sphinx/builders/latex/util.py
index 117e82e08..b7d79121c 100644
--- a/sphinx/builders/latex/util.py
+++ b/sphinx/builders/latex/util.py
@@ -14,23 +14,19 @@ from docutils.writers.latex2e import Babel
class ExtBabel(Babel):
cyrillic_languages = ('bulgarian', 'kazakh', 'mongolian', 'russian', 'ukrainian')
- def __init__(self, language_code, use_polyglossia=False):
- # type: (str, bool) -> None
+ def __init__(self, language_code: str, use_polyglossia: bool = False) -> None:
self.language_code = language_code
self.use_polyglossia = use_polyglossia
self.supported = True
super().__init__(language_code or '')
- def uses_cyrillic(self):
- # type: () -> bool
+ def uses_cyrillic(self) -> bool:
return self.language in self.cyrillic_languages
- def is_supported_language(self):
- # type: () -> bool
+ def is_supported_language(self) -> bool:
return self.supported
- def language_name(self, language_code):
- # type: (str) -> str
+ def language_name(self, language_code: str) -> str:
language = super().language_name(language_code)
if language == 'ngerman' and self.use_polyglossia:
# polyglossia calls new orthography (Neue Rechtschreibung) as
@@ -44,8 +40,7 @@ class ExtBabel(Babel):
self.supported = False
return 'english' # fallback to english
- def get_mainlanguage_options(self):
- # type: () -> str
+ def get_mainlanguage_options(self) -> str:
"""Return options for polyglossia's ``\\setmainlanguage``."""
if self.use_polyglossia is False:
return None
diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py
index 8b7c7ba9a..14aa1c530 100644
--- a/sphinx/builders/linkcheck.py
+++ b/sphinx/builders/linkcheck.py
@@ -14,11 +14,14 @@ import socket
import threading
from html.parser import HTMLParser
from os import path
+from typing import Any, Dict, List, Set, Tuple
from urllib.parse import unquote
from docutils import nodes
+from docutils.nodes import Node
from requests.exceptions import HTTPError
+from sphinx.application import Sphinx
from sphinx.builders import Builder
from sphinx.locale import __
from sphinx.util import encode_uri, requests, logging
@@ -28,12 +31,6 @@ from sphinx.util.console import ( # type: ignore
from sphinx.util.nodes import get_node_line
from sphinx.util.requests import is_ssl_error
-if False:
- # For type annotation
- from typing import Any, Dict, List, Set, Tuple # NOQA
- from sphinx.application import Sphinx # NOQA
- from sphinx.util.requests.requests import Response # NOQA
-
logger = logging.getLogger(__name__)
@@ -41,23 +38,20 @@ logger = logging.getLogger(__name__)
class AnchorCheckParser(HTMLParser):
"""Specialized HTML parser that looks for a specific anchor."""
- def __init__(self, search_anchor):
- # type: (str) -> None
+ def __init__(self, search_anchor: str) -> None:
super().__init__()
self.search_anchor = search_anchor
self.found = False
- def handle_starttag(self, tag, attrs):
- # type: (Any, Any) -> None
+ def handle_starttag(self, tag: Any, attrs: Any) -> None:
for key, value in attrs:
if key in ('id', 'name') and value == self.search_anchor:
self.found = True
break
-def check_anchor(response, anchor):
- # type: (Response, str) -> bool
+def check_anchor(response: requests.requests.Response, anchor: str) -> bool:
"""Reads HTML data from a response object `response` searching for `anchor`.
Returns True if anchor was found, False otherwise.
"""
@@ -80,8 +74,7 @@ class CheckExternalLinksBuilder(Builder):
epilog = __('Look for any errors in the above output or in '
'%(outdir)s/output.txt')
- def init(self):
- # type: () -> None
+ def init(self) -> None:
self.to_ignore = [re.compile(x) for x in self.app.config.linkcheck_ignore]
self.anchors_ignore = [re.compile(x)
for x in self.app.config.linkcheck_anchors_ignore]
@@ -103,8 +96,7 @@ class CheckExternalLinksBuilder(Builder):
thread.start()
self.workers.append(thread)
- def check_thread(self):
- # type: () -> None
+ def check_thread(self) -> None:
kwargs = {
'allow_redirects': True,
'headers': {
@@ -115,8 +107,7 @@ class CheckExternalLinksBuilder(Builder):
if self.app.config.linkcheck_timeout:
kwargs['timeout'] = self.app.config.linkcheck_timeout
- def check_uri():
- # type: () -> Tuple[str, str, int]
+ def check_uri() -> Tuple[str, str, int]:
# split off anchor
if '#' in uri:
req_url, anchor = uri.split('#', 1)
@@ -182,8 +173,7 @@ class CheckExternalLinksBuilder(Builder):
else:
return 'redirected', new_url, 0
- def check():
- # type: () -> Tuple[str, str, int]
+ def check() -> Tuple[str, str, int]:
# check for various conditions without bothering the network
if len(uri) == 0 or uri.startswith(('#', 'mailto:', 'ftp:')):
return 'unchecked', '', 0
@@ -221,8 +211,7 @@ class CheckExternalLinksBuilder(Builder):
status, info, code = check()
self.rqueue.put((uri, docname, lineno, status, info, code))
- def process_result(self, result):
- # type: (Tuple[str, str, int, str, str, int]) -> None
+ def process_result(self, result: Tuple[str, str, int, str, str, int]) -> None:
uri, docname, lineno, status, info, code = result
if status == 'unchecked':
return
@@ -259,20 +248,16 @@ class CheckExternalLinksBuilder(Builder):
uri + ' to ' + info)
logger.info(color('redirect ') + uri + color(' - ' + text + ' to ' + info))
- def get_target_uri(self, docname, typ=None):
- # type: (str, str) -> str
+ def get_target_uri(self, docname: str, typ: str = None) -> str:
return ''
- def get_outdated_docs(self):
- # type: () -> Set[str]
+ def get_outdated_docs(self) -> Set[str]:
return self.env.found_docs
- def prepare_writing(self, docnames):
- # type: (Set[str]) -> None
+ def prepare_writing(self, docnames: Set[str]) -> None:
return
- def write_doc(self, docname, doctree):
- # type: (str, nodes.Node) -> None
+ def write_doc(self, docname: str, doctree: Node) -> None:
logger.info('')
n = 0
@@ -301,20 +286,17 @@ class CheckExternalLinksBuilder(Builder):
if self.broken:
self.app.statuscode = 1
- def write_entry(self, what, docname, line, uri):
- # type: (str, str, int, str) -> None
+ def write_entry(self, what: str, docname: str, line: int, uri: str) -> None:
with open(path.join(self.outdir, 'output.txt'), 'a', encoding='utf-8') as output:
output.write("%s:%s: [%s] %s\n" % (self.env.doc2path(docname, None),
line, what, uri))
- def finish(self):
- # type: () -> None
+ def finish(self) -> None:
for worker in self.workers:
self.wqueue.put((None, None, None), False)
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
app.add_builder(CheckExternalLinksBuilder)
app.add_config_value('linkcheck_ignore', [], None)
diff --git a/sphinx/builders/manpage.py b/sphinx/builders/manpage.py
index 5e424547c..94b312e36 100644
--- a/sphinx/builders/manpage.py
+++ b/sphinx/builders/manpage.py
@@ -9,12 +9,15 @@
"""
from os import path
+from typing import Any, Dict, List, Set, Tuple, Union
from docutils.frontend import OptionParser
from docutils.io import FileOutput
from sphinx import addnodes
+from sphinx.application import Sphinx
from sphinx.builders import Builder
+from sphinx.config import Config
from sphinx.errors import NoUri
from sphinx.locale import __
from sphinx.util import logging
@@ -24,12 +27,6 @@ from sphinx.util.nodes import inline_all_toctrees
from sphinx.util.osutil import make_filename_from_project
from sphinx.writers.manpage import ManualPageWriter, ManualPageTranslator
-if False:
- # For type annotation
- from typing import Any, Dict, List, Set, Tuple, Union # NOQA
- from sphinx.application import Sphinx # NOQA
- from sphinx.config import Config # NOQA
-
logger = logging.getLogger(__name__)
@@ -45,25 +42,21 @@ class ManualPageBuilder(Builder):
default_translator_class = ManualPageTranslator
supported_image_types = [] # type: List[str]
- def init(self):
- # type: () -> None
+ def init(self) -> None:
if not self.config.man_pages:
logger.warning(__('no "man_pages" config value found; no manual pages '
'will be written'))
- def get_outdated_docs(self):
- # type: () -> Union[str, List[str]]
+ def get_outdated_docs(self) -> Union[str, List[str]]:
return 'all manpages' # for now
- def get_target_uri(self, docname, typ=None):
- # type: (str, str) -> str
+ def get_target_uri(self, docname: str, typ: str = None) -> str:
if typ == 'token':
return ''
raise NoUri
@progress_message(__('writing'))
- def write(self, *ignored):
- # type: (Any) -> None
+ def write(self, *ignored) -> None:
docwriter = ManualPageWriter(self)
docsettings = OptionParser(
defaults=self.env.settings,
@@ -106,21 +99,18 @@ class ManualPageBuilder(Builder):
docwriter.write(largetree, destination)
- def finish(self):
- # type: () -> None
+ def finish(self) -> None:
pass
-def default_man_pages(config):
- # type: (Config) -> List[Tuple[str, str, str, List[str], int]]
+def default_man_pages(config: Config) -> List[Tuple[str, str, str, List[str], int]]:
""" Better default man_pages settings. """
filename = make_filename_from_project(config.project)
return [(config.master_doc, filename, '%s %s' % (config.project, config.release),
[config.author], 1)]
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
app.add_builder(ManualPageBuilder)
app.add_config_value('man_pages', default_man_pages, None)
diff --git a/sphinx/builders/qthelp.py b/sphinx/builders/qthelp.py
index d87246148..4053f437f 100644
--- a/sphinx/builders/qthelp.py
+++ b/sphinx/builders/qthelp.py
@@ -9,17 +9,14 @@
"""
import warnings
+from typing import Any, Dict
from sphinxcontrib.qthelp import QtHelpBuilder, render_file
import sphinx
+from sphinx.application import Sphinx
from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
-if False:
- # For type annotation
- from typing import Any, Dict # NOQA
- from sphinx.application import Sphinx # NOQA
-
deprecated_alias('sphinx.builders.qthelp',
{
@@ -29,8 +26,7 @@ deprecated_alias('sphinx.builders.qthelp',
RemovedInSphinx40Warning)
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
warnings.warn('sphinx.builders.qthelp has been moved to sphinxcontrib-qthelp.',
RemovedInSphinx40Warning)
diff --git a/sphinx/builders/singlehtml.py b/sphinx/builders/singlehtml.py
index 068d1c1c2..3309b024c 100644
--- a/sphinx/builders/singlehtml.py
+++ b/sphinx/builders/singlehtml.py
@@ -9,9 +9,12 @@
"""
from os import path
+from typing import Any, Dict, List, Tuple, Union
from docutils import nodes
+from docutils.nodes import Node
+from sphinx.application import Sphinx
from sphinx.builders.html import StandaloneHTMLBuilder
from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
from sphinx.environment.adapters.toctree import TocTree
@@ -21,11 +24,6 @@ from sphinx.util import progress_message
from sphinx.util.console import darkgreen # type: ignore
from sphinx.util.nodes import inline_all_toctrees
-if False:
- # For type annotation
- from typing import Any, Dict, List, Tuple, Union # NOQA
- from sphinx.application import Sphinx # NOQA
-
logger = logging.getLogger(__name__)
@@ -39,12 +37,10 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder):
copysource = False
- def get_outdated_docs(self): # type: ignore
- # type: () -> Union[str, List[str]]
+ def get_outdated_docs(self) -> Union[str, List[str]]: # type: ignore
return 'all documents'
- def get_target_uri(self, docname, typ=None):
- # type: (str, str) -> str
+ def get_target_uri(self, docname: str, typ: str = None) -> str:
if docname in self.env.all_docs:
# all references are on the same page...
return self.config.master_doc + self.out_suffix + \
@@ -53,13 +49,11 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder):
# chances are this is a html_additional_page
return docname + self.out_suffix
- def get_relative_uri(self, from_, to, typ=None):
- # type: (str, str, str) -> str
+ def get_relative_uri(self, from_: str, to: str, typ: str = None) -> str:
# ignore source
return self.get_target_uri(to, typ)
- def fix_refuris(self, tree):
- # type: (nodes.Node) -> None
+ def fix_refuris(self, tree: Node) -> None:
# fix refuris with double anchor
fname = self.config.master_doc + self.out_suffix
for refnode in tree.traverse(nodes.reference):
@@ -73,8 +67,7 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder):
if hashindex >= 0:
refnode['refuri'] = fname + refuri[hashindex:]
- def _get_local_toctree(self, docname, collapse=True, **kwds):
- # type: (str, bool, Any) -> str
+ def _get_local_toctree(self, docname: str, collapse: bool = True, **kwds) -> str:
if 'includehidden' not in kwds:
kwds['includehidden'] = False
toctree = TocTree(self.env).get_toctree_for(docname, self, collapse, **kwds)
@@ -82,8 +75,7 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder):
self.fix_refuris(toctree)
return self.render_partial(toctree)['fragment']
- def assemble_doctree(self):
- # type: () -> nodes.document
+ def assemble_doctree(self) -> nodes.document:
master = self.config.master_doc
tree = self.env.get_doctree(master)
tree = inline_all_toctrees(self, set(), master, tree, darkgreen, [master])
@@ -92,8 +84,7 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder):
self.fix_refuris(tree)
return tree
- def assemble_toc_secnumbers(self):
- # type: () -> Dict[str, Dict[str, Tuple[int, ...]]]
+ def assemble_toc_secnumbers(self) -> Dict[str, Dict[str, Tuple[int, ...]]]:
# Assemble toc_secnumbers to resolve section numbers on SingleHTML.
# Merge all secnumbers to single secnumber.
#
@@ -111,8 +102,7 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder):
return {self.config.master_doc: new_secnumbers}
- def assemble_toc_fignumbers(self):
- # type: () -> Dict[str, Dict[str, Dict[str, Tuple[int, ...]]]]
+ def assemble_toc_fignumbers(self) -> Dict[str, Dict[str, Dict[str, Tuple[int, ...]]]]:
# Assemble toc_fignumbers to resolve figure numbers on SingleHTML.
# Merge all fignumbers to single fignumber.
#
@@ -133,8 +123,7 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder):
return {self.config.master_doc: new_fignumbers}
- def get_doc_context(self, docname, body, metatags):
- # type: (str, str, str) -> Dict
+ def get_doc_context(self, docname: str, body: str, metatags: str) -> Dict:
# no relation links...
toctree = TocTree(self.env).get_toctree_for(self.config.master_doc, self, False)
# if there is no toctree, toc is None
@@ -160,8 +149,7 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder):
'display_toc': display_toc,
}
- def write(self, *ignored):
- # type: (Any) -> None
+ def write(self, *ignored) -> None:
docnames = self.env.all_docs
with progress_message(__('preparing documents')):
@@ -176,8 +164,7 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder):
self.write_doc_serialized(self.config.master_doc, doctree)
self.write_doc(self.config.master_doc, doctree)
- def finish(self):
- # type: () -> None
+ def finish(self) -> None:
self.write_additional_files()
self.copy_image_files()
self.copy_download_files()
@@ -187,8 +174,7 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder):
self.dump_inventory()
@progress_message(__('writing additional files'))
- def write_additional_files(self):
- # type: () -> None
+ def write_additional_files(self) -> None:
# no indices or search pages are supported
# additional pages from conf.py
@@ -210,8 +196,7 @@ deprecated_alias('sphinx.builders.html',
RemovedInSphinx40Warning)
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
app.setup_extension('sphinx.builders.html')
app.add_builder(SingleFileHTMLBuilder)
diff --git a/sphinx/builders/texinfo.py b/sphinx/builders/texinfo.py
index 301f30fe0..16f81c666 100644
--- a/sphinx/builders/texinfo.py
+++ b/sphinx/builders/texinfo.py
@@ -10,6 +10,7 @@
import os
from os import path
+from typing import Any, Dict, Iterable, List, Tuple, Union
from docutils import nodes
from docutils.frontend import OptionParser
@@ -17,7 +18,9 @@ from docutils.io import FileOutput
from sphinx import addnodes
from sphinx import package_dir
+from sphinx.application import Sphinx
from sphinx.builders import Builder
+from sphinx.config import Config
from sphinx.environment.adapters.asset import ImageAdapter
from sphinx.errors import NoUri
from sphinx.locale import _, __
@@ -30,12 +33,6 @@ from sphinx.util.nodes import inline_all_toctrees
from sphinx.util.osutil import SEP, ensuredir, make_filename_from_project
from sphinx.writers.texinfo import TexinfoWriter, TexinfoTranslator
-if False:
- # For type annotation
- from sphinx.application import Sphinx # NOQA
- from sphinx.config import Config # NOQA
- from typing import Any, Dict, Iterable, List, Tuple, Union # NOQA
-
logger = logging.getLogger(__name__)
template_dir = os.path.join(package_dir, 'templates', 'texinfo')
@@ -57,29 +54,24 @@ class TexinfoBuilder(Builder):
'image/gif']
default_translator_class = TexinfoTranslator
- def init(self):
- # type: () -> None
+ def init(self) -> None:
self.docnames = [] # type: Iterable[str]
self.document_data = [] # type: List[Tuple[str, str, str, str, str, str, str, bool]]
- def get_outdated_docs(self):
- # type: () -> Union[str, List[str]]
+ def get_outdated_docs(self) -> Union[str, List[str]]:
return 'all documents' # for now
- def get_target_uri(self, docname, typ=None):
- # type: (str, str) -> str
+ def get_target_uri(self, docname: str, typ: str = None) -> str:
if docname not in self.docnames:
raise NoUri
else:
return '%' + docname
- def get_relative_uri(self, from_, to, typ=None):
- # type: (str, str, str) -> str
+ def get_relative_uri(self, from_: str, to: str, typ: str = None) -> str:
# ignore source path
return self.get_target_uri(to, typ)
- def init_document_data(self):
- # type: () -> None
+ def init_document_data(self) -> None:
preliminary_document_data = [list(x) for x in self.config.texinfo_documents]
if not preliminary_document_data:
logger.warning(__('no "texinfo_documents" config value found; no documents '
@@ -98,8 +90,7 @@ class TexinfoBuilder(Builder):
docname = docname[:-5]
self.titles.append((docname, entry[2]))
- def write(self, *ignored):
- # type: (Any) -> None
+ def write(self, *ignored) -> None:
self.init_document_data()
for entry in self.document_data:
docname, targetname, title, author = entry[:4]
@@ -136,8 +127,7 @@ class TexinfoBuilder(Builder):
docwriter.write(doctree, destination)
self.copy_image_files(targetname[:-5])
- def assemble_doctree(self, indexfile, toctree_only, appendices):
- # type: (str, bool, List[str]) -> nodes.document
+ def assemble_doctree(self, indexfile: str, toctree_only: bool, appendices: List[str]) -> nodes.document: # NOQA
self.docnames = set([indexfile] + appendices)
logger.info(darkgreen(indexfile) + " ", nonl=True)
tree = self.env.get_doctree(indexfile)
@@ -179,12 +169,10 @@ class TexinfoBuilder(Builder):
pendingnode.replace_self(newnodes)
return largetree
- def finish(self):
- # type: () -> None
+ def finish(self) -> None:
self.copy_support_files()
- def copy_image_files(self, targetname):
- # type: (str) -> None
+ def copy_image_files(self, targetname: str) -> None:
if self.images:
stringify_func = ImageAdapter(self.app.env).get_original_image_uri
for src in status_iterator(self.images, __('copying images... '), "brown",
@@ -199,8 +187,7 @@ class TexinfoBuilder(Builder):
logger.warning(__('cannot copy image file %r: %s'),
path.join(self.srcdir, src), err)
- def copy_support_files(self):
- # type: () -> None
+ def copy_support_files(self) -> None:
try:
with progress_message(__('copying Texinfo support files')):
logger.info('Makefile ', nonl=True)
@@ -209,16 +196,14 @@ class TexinfoBuilder(Builder):
logger.warning(__("error writing file Makefile: %s"), err)
-def default_texinfo_documents(config):
- # type: (Config) -> List[Tuple[str, str, str, str, str, str, str]]
+def default_texinfo_documents(config: Config) -> List[Tuple[str, str, str, str, str, str, str]]: # NOQA
""" Better default texinfo_documents settings. """
filename = make_filename_from_project(config.project)
return [(config.master_doc, filename, config.project, config.author, filename,
'One line description of project', 'Miscellaneous')]
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
app.add_builder(TexinfoBuilder)
app.add_config_value('texinfo_documents', default_texinfo_documents, None)
diff --git a/sphinx/builders/text.py b/sphinx/builders/text.py
index d0875161d..475513cf9 100644
--- a/sphinx/builders/text.py
+++ b/sphinx/builders/text.py
@@ -9,21 +9,18 @@
"""
from os import path
+from typing import Any, Dict, Iterator, Set, Tuple
from docutils.io import StringOutput
+from docutils.nodes import Node
+from sphinx.application import Sphinx
from sphinx.builders import Builder
from sphinx.locale import __
from sphinx.util import logging
from sphinx.util.osutil import ensuredir, os_path
from sphinx.writers.text import TextWriter, TextTranslator
-if False:
- # For type annotation
- from typing import Any, Dict, Iterator, Set, Tuple # NOQA
- from docutils import nodes # NOQA
- from sphinx.application import Sphinx # NOQA
-
logger = logging.getLogger(__name__)
@@ -38,13 +35,11 @@ class TextBuilder(Builder):
current_docname = None # type: str
- def init(self):
- # type: () -> None
+ def init(self) -> None:
# section numbers for headings in the currently visited document
self.secnumbers = {} # type: Dict[str, Tuple[int, ...]]
- def get_outdated_docs(self):
- # type: () -> Iterator[str]
+ def get_outdated_docs(self) -> Iterator[str]:
for docname in self.env.found_docs:
if docname not in self.env.all_docs:
yield docname
@@ -62,16 +57,13 @@ class TextBuilder(Builder):
# source doesn't exist anymore
pass
- def get_target_uri(self, docname, typ=None):
- # type: (str, str) -> str
+ def get_target_uri(self, docname: str, typ: str = None) -> str:
return ''
- def prepare_writing(self, docnames):
- # type: (Set[str]) -> None
+ def prepare_writing(self, docnames: Set[str]) -> None:
self.writer = TextWriter(self)
- def write_doc(self, docname, doctree):
- # type: (str, nodes.Node) -> None
+ def write_doc(self, docname: str, doctree: Node) -> None:
self.current_docname = docname
self.secnumbers = self.env.toc_secnumbers.get(docname, {})
destination = StringOutput(encoding='utf-8')
@@ -84,13 +76,11 @@ class TextBuilder(Builder):
except OSError as err:
logger.warning(__("error writing file %s: %s"), outfilename, err)
- def finish(self):
- # type: () -> None
+ def finish(self) -> None:
pass
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
app.add_builder(TextBuilder)
app.add_config_value('text_sectionchars', '*=-~"+`', 'env')
diff --git a/sphinx/builders/xml.py b/sphinx/builders/xml.py
index b3d12149b..4aaa0811d 100644
--- a/sphinx/builders/xml.py
+++ b/sphinx/builders/xml.py
@@ -9,23 +9,20 @@
"""
from os import path
+from typing import Any, Dict, Iterator, Set, Type, Union
from docutils import nodes
from docutils.io import StringOutput
+from docutils.nodes import Node
from docutils.writers.docutils_xml import XMLTranslator
+from sphinx.application import Sphinx
from sphinx.builders import Builder
from sphinx.locale import __
from sphinx.util import logging
from sphinx.util.osutil import ensuredir, os_path
from sphinx.writers.xml import XMLWriter, PseudoXMLWriter
-if False:
- # For type annotation
- from typing import Any, Dict, Iterator, Set, Type # NOQA
- from docutils.writers.xml import BaseXMLWriter # NOQA
- from sphinx.application import Sphinx # NOQA
-
logger = logging.getLogger(__name__)
@@ -40,15 +37,13 @@ class XMLBuilder(Builder):
out_suffix = '.xml'
allow_parallel = True
- _writer_class = XMLWriter # type: Type[BaseXMLWriter]
+ _writer_class = XMLWriter # type: Union[Type[XMLWriter], Type[PseudoXMLWriter]]
default_translator_class = XMLTranslator
- def init(self):
- # type: () -> None
+ def init(self) -> None:
pass
- def get_outdated_docs(self):
- # type: () -> Iterator[str]
+ def get_outdated_docs(self) -> Iterator[str]:
for docname in self.env.found_docs:
if docname not in self.env.all_docs:
yield docname
@@ -66,16 +61,13 @@ class XMLBuilder(Builder):
# source doesn't exist anymore
pass
- def get_target_uri(self, docname, typ=None):
- # type: (str, str) -> str
+ def get_target_uri(self, docname: str, typ: str = None) -> str:
return docname
- def prepare_writing(self, docnames):
- # type: (Set[str]) -> None
+ def prepare_writing(self, docnames: Set[str]) -> None:
self.writer = self._writer_class(self)
- def write_doc(self, docname, doctree):
- # type: (str, nodes.Node) -> None
+ def write_doc(self, docname: str, doctree: Node) -> None:
# work around multiple string % tuple issues in docutils;
# replace tuples in attribute values with lists
doctree = doctree.deepcopy()
@@ -98,8 +90,7 @@ class XMLBuilder(Builder):
except OSError as err:
logger.warning(__("error writing file %s: %s"), outfilename, err)
- def finish(self):
- # type: () -> None
+ def finish(self) -> None:
pass
@@ -116,8 +107,7 @@ class PseudoXMLBuilder(XMLBuilder):
_writer_class = PseudoXMLWriter
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
app.add_builder(XMLBuilder)
app.add_builder(PseudoXMLBuilder)
diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py
index 972b62149..778648859 100644
--- a/sphinx/cmd/quickstart.py
+++ b/sphinx/cmd/quickstart.py
@@ -306,7 +306,7 @@ def ask_user(d):
'translate text that it generates into that language.\n'
'\n'
'For a list of supported codes, see\n'
- 'http://sphinx-doc.org/config.html#confval-language.'))
+ 'https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language.')) # NOQA
d['language'] = do_prompt(__('Project language'), 'en')
if d['language'] == 'en':
d['language'] = None
diff --git a/sphinx/directives/__init__.py b/sphinx/directives/__init__.py
index 40f838c48..13f48e827 100644
--- a/sphinx/directives/__init__.py
+++ b/sphinx/directives/__init__.py
@@ -9,23 +9,24 @@
"""
import re
-from typing import List, cast
+from typing import Any, Dict, List, Tuple
+from typing import cast
from docutils import nodes
+from docutils.nodes import Node
from docutils.parsers.rst import directives, roles
from sphinx import addnodes
+from sphinx.addnodes import desc_signature
from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
from sphinx.util import docutils
-from sphinx.util.docfields import DocFieldTransformer, TypedField
+from sphinx.util.docfields import DocFieldTransformer, Field, TypedField
from sphinx.util.docutils import SphinxDirective
+from sphinx.util.typing import DirectiveOption
if False:
# For type annotation
- from typing import Any, Dict, Tuple # NOQA
- from sphinx.application import Sphinx # NOQA
- from sphinx.util.docfields import Field # NOQA
- from sphinx.util.typing import DirectiveOption # NOQA
+ from sphinx.application import Sphinx
# RE to strip backslash escapes
@@ -70,8 +71,7 @@ class ObjectDescription(SphinxDirective):
# Warning: this might be removed in future version. Don't touch this from extensions.
_doc_field_type_map = {} # type: Dict[str, Tuple[Field, bool]]
- def get_field_type_map(self):
- # type: () -> Dict[str, Tuple[Field, bool]]
+ def get_field_type_map(self) -> Dict[str, Tuple[Field, bool]]:
if self._doc_field_type_map == {}:
for field in self.doc_field_types:
for name in field.names:
@@ -84,8 +84,7 @@ class ObjectDescription(SphinxDirective):
return self._doc_field_type_map
- def get_signatures(self):
- # type: () -> List[str]
+ def get_signatures(self) -> List[str]:
"""
Retrieve the signatures to document from the directive arguments. By
default, signatures are given as arguments, one per line.
@@ -96,8 +95,7 @@ class ObjectDescription(SphinxDirective):
# remove backslashes to support (dummy) escapes; helps Vim highlighting
return [strip_backslash_re.sub(r'\1', line.strip()) for line in lines]
- def handle_signature(self, sig, signode):
- # type: (str, addnodes.desc_signature) -> Any
+ def handle_signature(self, sig: str, signode: desc_signature) -> Any:
"""
Parse the signature *sig* into individual nodes and append them to
*signode*. If ValueError is raised, parsing is aborted and the whole
@@ -109,8 +107,7 @@ class ObjectDescription(SphinxDirective):
"""
raise ValueError
- def add_target_and_index(self, name, sig, signode):
- # type: (Any, str, addnodes.desc_signature) -> None
+ def add_target_and_index(self, name: Any, sig: str, signode: desc_signature) -> None:
"""
Add cross-reference IDs and entries to self.indexnode, if applicable.
@@ -118,24 +115,21 @@ class ObjectDescription(SphinxDirective):
"""
return # do nothing by default
- def before_content(self):
- # type: () -> None
+ def before_content(self) -> None:
"""
Called before parsing content. Used to set information about the current
directive context on the build environment.
"""
pass
- def after_content(self):
- # type: () -> None
+ def after_content(self) -> None:
"""
Called after parsing content. Used to reset information about the
current directive context on the build environment.
"""
pass
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
"""
Main directive entry function, called by docutils upon encountering the
directive.
@@ -212,8 +206,7 @@ class DefaultRole(SphinxDirective):
optional_arguments = 1
final_argument_whitespace = False
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
if not self.arguments:
docutils.unregister_role('')
return []
@@ -244,8 +237,7 @@ class DefaultDomain(SphinxDirective):
final_argument_whitespace = False
option_spec = {} # type: Dict
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
domain_name = self.arguments[0].lower()
# if domain_name not in env.domains:
# # try searching by label
@@ -294,8 +286,7 @@ deprecated_alias('sphinx.directives',
DescDirective = ObjectDescription
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: "Sphinx") -> Dict[str, Any]:
directives.register_directive('default-role', DefaultRole)
directives.register_directive('default-domain', DefaultDomain)
directives.register_directive('describe', ObjectDescription)
diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py
index ff21bcdab..aa5192f78 100644
--- a/sphinx/directives/code.py
+++ b/sphinx/directives/code.py
@@ -9,12 +9,15 @@
import sys
import warnings
from difflib import unified_diff
+from typing import Any, Dict, List, Tuple
from docutils import nodes
+from docutils.nodes import Element, Node
from docutils.parsers.rst import directives
from docutils.statemachine import StringList
from sphinx import addnodes
+from sphinx.config import Config
from sphinx.deprecation import RemovedInSphinx40Warning
from sphinx.locale import __
from sphinx.util import logging
@@ -23,9 +26,7 @@ from sphinx.util.docutils import SphinxDirective
if False:
# For type annotation
- from typing import Any, Dict, List, Tuple # NOQA
- from sphinx.application import Sphinx # NOQA
- from sphinx.config import Config # NOQA
+ from sphinx.application import Sphinx
logger = logging.getLogger(__name__)
@@ -45,8 +46,7 @@ class Highlight(SphinxDirective):
'linenothreshold': directives.positive_int,
}
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
language = self.arguments[0].strip()
linenothreshold = self.options.get('linenothreshold', sys.maxsize)
force = 'force' in self.options
@@ -60,16 +60,14 @@ class Highlight(SphinxDirective):
class HighlightLang(Highlight):
"""highlightlang directive (deprecated)"""
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
warnings.warn('highlightlang directive is deprecated. '
'Please use highlight directive instead.',
RemovedInSphinx40Warning, stacklevel=2)
return super().run()
-def dedent_lines(lines, dedent, location=None):
- # type: (List[str], int, Tuple[str, int]) -> List[str]
+def dedent_lines(lines: List[str], dedent: int, location: Tuple[str, int] = None) -> List[str]:
if not dedent:
return lines
@@ -86,8 +84,7 @@ def dedent_lines(lines, dedent, location=None):
return new_lines
-def container_wrapper(directive, literal_node, caption):
- # type: (SphinxDirective, nodes.Node, str) -> nodes.container
+def container_wrapper(directive: SphinxDirective, literal_node: Node, caption: str) -> nodes.container: # NOQA
container_node = nodes.container('', literal_block=True,
classes=['literal-block-wrapper'])
parsed = nodes.Element()
@@ -129,8 +126,7 @@ class CodeBlock(SphinxDirective):
'name': directives.unchanged,
}
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
document = self.state.document
code = '\n'.join(self.content)
location = self.state_machine.get_source_and_line(self.lineno)
@@ -157,7 +153,7 @@ class CodeBlock(SphinxDirective):
lines = dedent_lines(lines, self.options['dedent'], location=location)
code = '\n'.join(lines)
- literal = nodes.literal_block(code, code) # type: nodes.Element
+ literal = nodes.literal_block(code, code) # type: Element
if 'linenos' in self.options or 'lineno-start' in self.options:
literal['linenos'] = True
literal['classes'] += self.options.get('class', [])
@@ -209,8 +205,7 @@ class LiteralIncludeReader:
('diff', 'end-at'),
]
- def __init__(self, filename, options, config):
- # type: (str, Dict, Config) -> None
+ def __init__(self, filename: str, options: Dict, config: Config) -> None:
self.filename = filename
self.options = options
self.encoding = options.get('encoding', config.source_encoding)
@@ -218,15 +213,13 @@ class LiteralIncludeReader:
self.parse_options()
- def parse_options(self):
- # type: () -> None
+ def parse_options(self) -> None:
for option1, option2 in self.INVALID_OPTIONS_PAIR:
if option1 in self.options and option2 in self.options:
raise ValueError(__('Cannot use both "%s" and "%s" options') %
(option1, option2))
- def read_file(self, filename, location=None):
- # type: (str, Tuple[str, int]) -> List[str]
+ def read_file(self, filename: str, location: Tuple[str, int] = None) -> List[str]:
try:
with open(filename, encoding=self.encoding, errors='strict') as f:
text = f.read()
@@ -241,8 +234,7 @@ class LiteralIncludeReader:
'be wrong, try giving an :encoding: option') %
(self.encoding, filename))
- def read(self, location=None):
- # type: (Tuple[str, int]) -> Tuple[str, int]
+ def read(self, location: Tuple[str, int] = None) -> Tuple[str, int]:
if 'diff' in self.options:
lines = self.show_diff()
else:
@@ -259,16 +251,14 @@ class LiteralIncludeReader:
return ''.join(lines), len(lines)
- def show_diff(self, location=None):
- # type: (Tuple[str, int]) -> List[str]
+ def show_diff(self, location: Tuple[str, int] = None) -> List[str]:
new_lines = self.read_file(self.filename)
old_filename = self.options.get('diff')
old_lines = self.read_file(old_filename)
diff = unified_diff(old_lines, new_lines, old_filename, self.filename)
return list(diff)
- def pyobject_filter(self, lines, location=None):
- # type: (List[str], Tuple[str, int]) -> List[str]
+ def pyobject_filter(self, lines: List[str], location: Tuple[str, int] = None) -> List[str]:
pyobject = self.options.get('pyobject')
if pyobject:
from sphinx.pycode import ModuleAnalyzer
@@ -286,8 +276,7 @@ class LiteralIncludeReader:
return lines
- def lines_filter(self, lines, location=None):
- # type: (List[str], Tuple[str, int]) -> List[str]
+ def lines_filter(self, lines: List[str], location: Tuple[str, int] = None) -> List[str]:
linespec = self.options.get('lines')
if linespec:
linelist = parselinenos(linespec, len(lines))
@@ -311,8 +300,7 @@ class LiteralIncludeReader:
return lines
- def start_filter(self, lines, location=None):
- # type: (List[str], Tuple[str, int]) -> List[str]
+ def start_filter(self, lines: List[str], location: Tuple[str, int] = None) -> List[str]:
if 'start-at' in self.options:
start = self.options.get('start-at')
inclusive = False
@@ -343,8 +331,7 @@ class LiteralIncludeReader:
return lines
- def end_filter(self, lines, location=None):
- # type: (List[str], Tuple[str, int]) -> List[str]
+ def end_filter(self, lines: List[str], location: Tuple[str, int] = None) -> List[str]:
if 'end-at' in self.options:
end = self.options.get('end-at')
inclusive = True
@@ -371,24 +358,21 @@ class LiteralIncludeReader:
return lines
- def prepend_filter(self, lines, location=None):
- # type: (List[str], Tuple[str, int]) -> List[str]
+ def prepend_filter(self, lines: List[str], location: Tuple[str, int] = None) -> List[str]:
prepend = self.options.get('prepend')
if prepend:
lines.insert(0, prepend + '\n')
return lines
- def append_filter(self, lines, location=None):
- # type: (List[str], Tuple[str, int]) -> List[str]
+ def append_filter(self, lines: List[str], location: Tuple[str, int] = None) -> List[str]:
append = self.options.get('append')
if append:
lines.append(append + '\n')
return lines
- def dedent_filter(self, lines, location=None):
- # type: (List[str], Tuple[str, int]) -> List[str]
+ def dedent_filter(self, lines: List[str], location: Tuple[str, int] = None) -> List[str]:
if 'dedent' in self.options:
return dedent_lines(lines, self.options.get('dedent'), location=location)
else:
@@ -430,8 +414,7 @@ class LiteralInclude(SphinxDirective):
'diff': directives.unchanged_required,
}
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
document = self.state.document
if not document.settings.file_insertion_enabled:
return [document.reporter.warning('File insertion disabled',
@@ -449,7 +432,7 @@ class LiteralInclude(SphinxDirective):
reader = LiteralIncludeReader(filename, self.options, self.config)
text, lines = reader.read(location=location)
- retnode = nodes.literal_block(text, text, source=filename) # type: nodes.Element
+ retnode = nodes.literal_block(text, text, source=filename) # type: Element
retnode['force'] = 'force' in self.options
self.set_source_info(retnode)
if self.options.get('diff'): # if diff is set, set udiff
@@ -483,8 +466,7 @@ class LiteralInclude(SphinxDirective):
return [document.reporter.warning(exc, line=self.lineno)]
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: "Sphinx") -> Dict[str, Any]:
directives.register_directive('highlight', Highlight)
directives.register_directive('highlightlang', HighlightLang)
directives.register_directive('code-block', CodeBlock)
diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py
index 5863541bf..1113e8241 100644
--- a/sphinx/directives/other.py
+++ b/sphinx/directives/other.py
@@ -7,9 +7,11 @@
"""
import re
+from typing import Any, Dict, List
from typing import cast
from docutils import nodes
+from docutils.nodes import Element, Node
from docutils.parsers.rst import directives
from docutils.parsers.rst.directives.admonitions import BaseAdmonition
from docutils.parsers.rst.directives.misc import Class
@@ -25,15 +27,13 @@ from sphinx.util.nodes import explicit_title_re, process_index_entry
if False:
# For type annotation
- from typing import Any, Dict, List # NOQA
- from sphinx.application import Sphinx # NOQA
+ from sphinx.application import Sphinx
glob_re = re.compile(r'.*[*?\[].*')
-def int_or_nothing(argument):
- # type: (str) -> int
+def int_or_nothing(argument: str) -> int:
if not argument:
return 999
return int(argument)
@@ -60,8 +60,7 @@ class TocTree(SphinxDirective):
'reversed': directives.flag,
}
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
subnode = addnodes.toctree()
subnode['parent'] = self.env.docname
@@ -160,11 +159,10 @@ class Author(SphinxDirective):
final_argument_whitespace = True
option_spec = {} # type: Dict
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
if not self.config.show_authors:
return []
- para = nodes.paragraph(translatable=False) # type: nodes.Element
+ para = nodes.paragraph(translatable=False) # type: Element
emph = nodes.emphasis()
para += emph
if self.name == 'sectionauthor':
@@ -179,7 +177,7 @@ class Author(SphinxDirective):
inodes, messages = self.state.inline_text(self.arguments[0], self.lineno)
emph.extend(inodes)
- ret = [para] # type: List[nodes.Node]
+ ret = [para] # type: List[Node]
ret += messages
return ret
@@ -194,8 +192,7 @@ class Index(SphinxDirective):
final_argument_whitespace = True
option_spec = {} # type: Dict
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
arguments = self.arguments[0].split('\n')
targetid = 'index-%s' % self.env.new_serialno('index')
targetnode = nodes.target('', '', ids=[targetid])
@@ -226,8 +223,7 @@ class TabularColumns(SphinxDirective):
final_argument_whitespace = True
option_spec = {} # type: Dict
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
node = addnodes.tabular_col_spec()
node['spec'] = self.arguments[0]
self.set_source_info(node)
@@ -244,15 +240,14 @@ class Centered(SphinxDirective):
final_argument_whitespace = True
option_spec = {} # type: Dict
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
if not self.arguments:
return []
- subnode = addnodes.centered() # type: nodes.Element
+ subnode = addnodes.centered() # type: Element
inodes, messages = self.state.inline_text(self.arguments[0], self.lineno)
subnode.extend(inodes)
- ret = [subnode] # type: List[nodes.Node]
+ ret = [subnode] # type: List[Node]
ret += messages
return ret
@@ -267,8 +262,7 @@ class Acks(SphinxDirective):
final_argument_whitespace = False
option_spec = {} # type: Dict
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
node = addnodes.acks()
node.document = self.state.document
self.state.nested_parse(self.content, self.content_offset, node)
@@ -291,8 +285,7 @@ class HList(SphinxDirective):
'columns': int,
}
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
ncolumns = self.options.get('columns', 2)
node = nodes.paragraph()
node.document = self.state.document
@@ -325,8 +318,7 @@ class Only(SphinxDirective):
final_argument_whitespace = True
option_spec = {} # type: Dict
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
node = addnodes.only()
node.document = self.state.document
self.set_source_info(node)
@@ -380,8 +372,7 @@ class Include(BaseInclude, SphinxDirective):
"correctly", i.e. relative to source directory.
"""
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
if self.arguments[0].startswith('<') and \
self.arguments[0].endswith('>'):
# docutils "standard" includes, do not do path processing
@@ -392,8 +383,7 @@ class Include(BaseInclude, SphinxDirective):
return super().run()
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: "Sphinx") -> Dict[str, Any]:
directives.register_directive('toctree', TocTree)
directives.register_directive('sectionauthor', Author)
directives.register_directive('moduleauthor', Author)
diff --git a/sphinx/directives/patches.py b/sphinx/directives/patches.py
index 189e1f7e3..b4b1664ab 100644
--- a/sphinx/directives/patches.py
+++ b/sphinx/directives/patches.py
@@ -6,10 +6,11 @@
:license: BSD, see LICENSE for details.
"""
+from typing import Any, Dict, List, Tuple
from typing import cast
from docutils import nodes
-from docutils.nodes import make_id
+from docutils.nodes import Node, make_id, system_message
from docutils.parsers.rst import directives
from docutils.parsers.rst.directives import images, html, tables
@@ -20,8 +21,7 @@ from sphinx.util.nodes import set_source_info
if False:
# For type annotation
- from typing import Dict, List, Tuple # NOQA
- from sphinx.application import Sphinx # NOQA
+ from sphinx.application import Sphinx
class Figure(images.Figure):
@@ -29,8 +29,7 @@ class Figure(images.Figure):
instead of the image node.
"""
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
name = self.options.pop('name', None)
result = super().run()
if len(result) == 2 or isinstance(result[0], nodes.system_message):
@@ -52,8 +51,7 @@ class Figure(images.Figure):
class Meta(html.Meta, SphinxDirective):
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
result = super().run()
for node in result:
if (isinstance(node, nodes.pending) and
@@ -74,8 +72,7 @@ class RSTTable(tables.RSTTable):
Only for docutils-0.13 or older version."""
- def make_title(self):
- # type: () -> Tuple[nodes.title, List[nodes.system_message]]
+ def make_title(self) -> Tuple[nodes.title, List[system_message]]:
title, message = super().make_title()
if title:
set_source_info(self, title)
@@ -88,8 +85,7 @@ class CSVTable(tables.CSVTable):
Only for docutils-0.13 or older version."""
- def make_title(self):
- # type: () -> Tuple[nodes.title, List[nodes.system_message]]
+ def make_title(self) -> Tuple[nodes.title, List[system_message]]:
title, message = super().make_title()
if title:
set_source_info(self, title)
@@ -102,8 +98,7 @@ class ListTable(tables.ListTable):
Only for docutils-0.13 or older version."""
- def make_title(self):
- # type: () -> Tuple[nodes.title, List[nodes.system_message]]
+ def make_title(self) -> Tuple[nodes.title, List[system_message]]:
title, message = super().make_title()
if title:
set_source_info(self, title)
@@ -125,8 +120,7 @@ class Code(SphinxDirective):
}
has_content = True
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
self.assert_has_content()
code = '\n'.join(self.content)
@@ -169,8 +163,7 @@ class MathDirective(SphinxDirective):
'nowrap': directives.flag,
}
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
latex = '\n'.join(self.content)
if self.arguments and self.arguments[0]:
latex = self.arguments[0] + '\n\n' + latex
@@ -184,12 +177,11 @@ class MathDirective(SphinxDirective):
self.add_name(node)
self.set_source_info(node)
- ret = [node] # type: List[nodes.Node]
+ ret = [node] # type: List[Node]
self.add_target(ret)
return ret
- def add_target(self, ret):
- # type: (List[nodes.Node]) -> None
+ def add_target(self, ret: List[Node]) -> None:
node = cast(nodes.math_block, ret[0])
# assign label automatically if math_number_all enabled
@@ -216,8 +208,7 @@ class MathDirective(SphinxDirective):
self.state_machine.reporter.warning(exc, line=self.lineno)
-def setup(app):
- # type: (Sphinx) -> Dict
+def setup(app: "Sphinx") -> Dict[str, Any]:
directives.register_directive('figure', Figure)
directives.register_directive('meta', Meta)
directives.register_directive('table', RSTTable)
diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py
index ed7090b6c..07bf54e10 100644
--- a/sphinx/ext/autodoc/__init__.py
+++ b/sphinx/ext/autodoc/__init__.py
@@ -547,10 +547,8 @@ class Documenter:
if self.analyzer:
attr_docs = self.analyzer.find_attr_docs()
- tagorder = self.analyzer.tagorder
else:
attr_docs = {}
- tagorder = {}
# process members and determine which to skip
for (membername, member) in members:
@@ -580,13 +578,12 @@ class Documenter:
membername in self.options.special_members:
keep = has_doc or self.options.undoc_members
elif (namespace, membername) in attr_docs:
- has_doc = bool(attr_docs[namespace, membername])
if want_all and membername.startswith('_'):
# ignore members whose name starts with _ by default
- keep = has_doc and self.options.private_members
+ keep = self.options.private_members
else:
# keep documented attributes
- keep = has_doc
+ keep = True
isattr = True
elif want_all and membername.startswith('_'):
# ignore members whose name starts with _ by default
@@ -595,8 +592,6 @@ class Documenter:
else:
# ignore undocumented members if :undoc-members: is not given
keep = has_doc or self.options.undoc_members
- # module top level item or not
- isattr = membername in tagorder
# give the user a chance to decide whether this member
# should be skipped
@@ -1294,10 +1289,6 @@ class DataDocumenter(ModuleLevelDocumenter):
return self.get_attr(self.parent or self.object, '__module__', None) \
or self.modname
- def get_doc(self, encoding=None, ignore=1):
- # type: (str, int) -> List[List[str]]
- return []
-
class MethodDocumenter(DocstringSignatureMixin, ClassLevelDocumenter): # type: ignore
"""
diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py
index 262b36cea..6eb0fea9b 100644
--- a/sphinx/ext/autosummary/__init__.py
+++ b/sphinx/ext/autosummary/__init__.py
@@ -754,7 +754,6 @@ def process_generate_options(app):
imported_members = app.config.autosummary_imported_members
with mock(app.config.autosummary_mock_imports):
generate_autosummary_docs(genfiles, builder=app.builder,
- warn=logger.warning, info=logger.info,
suffix=suffix, base_path=app.srcdir,
app=app, imported_members=imported_members)
diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py
index 1bfbb0da4..4a699dd9f 100644
--- a/sphinx/ext/autosummary/generate.py
+++ b/sphinx/ext/autosummary/generate.py
@@ -23,6 +23,7 @@ import os
import pydoc
import re
import sys
+import warnings
from jinja2 import BaseLoader, FileSystemLoader, TemplateNotFound
from jinja2.sandbox import SandboxedEnvironment
@@ -30,10 +31,12 @@ from jinja2.sandbox import SandboxedEnvironment
import sphinx.locale
from sphinx import __display_version__
from sphinx import package_dir
+from sphinx.deprecation import RemovedInSphinx40Warning
from sphinx.ext.autosummary import import_by_name, get_documenter
from sphinx.jinja2glue import BuiltinTemplateLoader
from sphinx.locale import __
from sphinx.registry import SphinxComponentRegistry
+from sphinx.util import logging
from sphinx.util import rst
from sphinx.util.inspect import safe_getattr
from sphinx.util.osutil import ensuredir
@@ -45,12 +48,17 @@ if False:
from sphinx.ext.autodoc import Documenter # NOQA
+logger = logging.getLogger(__name__)
+
+
class DummyApplication:
"""Dummy Application class for sphinx-autogen command."""
def __init__(self):
# type: () -> None
self.registry = SphinxComponentRegistry()
+ self.messagelog = [] # type: List[str]
+ self.verbosity = 0
def setup_documenters(app):
@@ -127,10 +135,20 @@ class AutosummaryRenderer:
# -- Generating output ---------------------------------------------------------
def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
- warn=_simple_warn, info=_simple_info,
- base_path=None, builder=None, template_dir=None,
- imported_members=False, app=None):
+ warn=None, info=None, base_path=None, builder=None,
+ template_dir=None, imported_members=False, app=None):
# type: (List[str], str, str, Callable, Callable, str, Builder, str, bool, Any) -> None
+ if info:
+ warnings.warn('info argument for generate_autosummary_docs() is deprecated.',
+ RemovedInSphinx40Warning)
+ else:
+ info = logger.info
+
+ if warn:
+ warnings.warn('warn argument for generate_autosummary_docs() is deprecated.',
+ RemovedInSphinx40Warning)
+ else:
+ warn = logger.warning
showed_sources = list(sorted(sources))
if len(showed_sources) > 20:
@@ -420,6 +438,7 @@ def main(argv=sys.argv[1:]):
sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
app = DummyApplication()
+ logging.setup(app, sys.stdout, sys.stderr) # type: ignore
setup_documenters(app)
args = get_parser().parse_args(argv)
generate_autosummary_docs(args.source_file, args.output_dir,
diff --git a/sphinx/ext/graphviz.py b/sphinx/ext/graphviz.py
index c602869cd..ab45b55fc 100644
--- a/sphinx/ext/graphviz.py
+++ b/sphinx/ext/graphviz.py
@@ -127,7 +127,8 @@ class Graphviz(SphinxDirective):
'alt': directives.unchanged,
'align': align_spec,
'caption': directives.unchanged,
- 'graphviz_dot': directives.unchanged,
+ 'layout': directives.unchanged,
+ 'graphviz_dot': directives.unchanged, # an old alias of `layout` option
'name': directives.unchanged,
}
@@ -161,6 +162,8 @@ class Graphviz(SphinxDirective):
if 'graphviz_dot' in self.options:
node['options']['graphviz_dot'] = self.options['graphviz_dot']
+ if 'layout' in self.options:
+ node['options']['graphviz_dot'] = self.options['layout']
if 'alt' in self.options:
node['alt'] = self.options['alt']
if 'align' in self.options:
diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py
index 0fea99fb8..7ff184961 100644
--- a/sphinx/ext/napoleon/docstring.py
+++ b/sphinx/ext/napoleon/docstring.py
@@ -328,6 +328,9 @@ class GoogleDocstring:
def _escape_args_and_kwargs(self, name):
# type: (str) -> str
+ if name.endswith('_'):
+ name = name[:-1] + r'\_'
+
if name[:2] == '**':
return r'\*\*' + name[2:]
elif name[:1] == '*':
@@ -555,7 +558,7 @@ class GoogleDocstring:
# type: () -> None
self._parsed_lines = self._consume_empty()
- if self._name and (self._what == 'attribute' or self._what == 'data'):
+ if self._name and self._what in ('attribute', 'data', 'property'):
# Implicit stop using StopIteration no longer allowed in
# Python 3.7; see PEP 479
res = [] # type: List[str]
diff --git a/sphinx/ext/todo.py b/sphinx/ext/todo.py
index f43520036..2da27700b 100644
--- a/sphinx/ext/todo.py
+++ b/sphinx/ext/todo.py
@@ -11,6 +11,7 @@
:license: BSD, see LICENSE for details.
"""
+import warnings
from typing import cast
from docutils import nodes
@@ -18,6 +19,8 @@ from docutils.parsers.rst import directives
from docutils.parsers.rst.directives.admonitions import BaseAdmonition
import sphinx
+from sphinx.deprecation import RemovedInSphinx40Warning
+from sphinx.domains import Domain
from sphinx.errors import NoUri
from sphinx.locale import _, __
from sphinx.util import logging
@@ -69,6 +72,7 @@ class Todo(BaseAdmonition, SphinxDirective):
return [todo]
elif isinstance(todo, todo_node):
todo.insert(0, nodes.title(text=_('Todo')))
+ todo['docname'] = self.env.docname
self.add_name(todo)
self.set_source_info(todo)
self.state.document.note_explicit_target(todo)
@@ -77,8 +81,39 @@ class Todo(BaseAdmonition, SphinxDirective):
raise RuntimeError # never reached here
+class TodoDomain(Domain):
+ name = 'todo'
+ label = 'todo'
+
+ @property
+ def todos(self):
+ # type: () -> Dict[str, List[todo_node]]
+ return self.data.setdefault('todos', {})
+
+ def clear_doc(self, docname):
+ # type: (str) -> None
+ self.todos.pop(docname, None)
+
+ def merge_domaindata(self, docnames, otherdata):
+ # type: (List[str], Dict) -> None
+ for docname in docnames:
+ self.todos[docname] = otherdata['todos'][docname]
+
+ def process_doc(self, env, docname, document):
+ # type: (BuildEnvironment, str, nodes.document) -> None
+ todos = self.todos.setdefault(docname, [])
+ for todo in document.traverse(todo_node):
+ env.app.emit('todo-defined', todo)
+ todos.append(todo)
+
+ if env.config.todo_emit_warnings:
+ logger.warning(__("TODO entry found: %s"), todo[1].astext(),
+ location=todo)
+
+
def process_todos(app, doctree):
# type: (Sphinx, nodes.document) -> None
+ warnings.warn('process_todos() is deprecated.', RemovedInSphinx40Warning)
# 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
@@ -122,19 +157,82 @@ class TodoList(SphinxDirective):
return [todolist('')]
+class TodoListProcessor:
+ def __init__(self, app, doctree, docname):
+ # type: (Sphinx, nodes.document, str) -> None
+ self.builder = app.builder
+ self.config = app.config
+ self.env = app.env
+ self.domain = cast(TodoDomain, app.env.get_domain('todo'))
+
+ self.process(doctree, docname)
+
+ def process(self, doctree, docname):
+ # type: (nodes.document, str) -> None
+ todos = sum(self.domain.todos.values(), [])
+ for node in doctree.traverse(todolist):
+ if not self.config.todo_include_todos:
+ node.parent.remove(node)
+ continue
+
+ if node.get('ids'):
+ content = [nodes.target()] # type: List[nodes.Element]
+ else:
+ content = []
+
+ for todo in todos:
+ # Create a copy of the todo node
+ new_todo = todo.deepcopy()
+ new_todo['ids'].clear()
+
+ # (Recursively) resolve references in the todo content
+ self.env.resolve_references(new_todo, todo['docname'], self.builder) # type: ignore # NOQA
+ content.append(new_todo)
+
+ todo_ref = self.create_todo_reference(todo, docname)
+ content.append(todo_ref)
+
+ node.replace_self(content)
+
+ def create_todo_reference(self, todo, docname):
+ # type: (todo_node, str) -> nodes.paragraph
+ if self.config.todo_link_only:
+ description = _('<<original entry>>')
+ else:
+ description = (_('(The <<original entry>> is located in %s, line %d.)') %
+ (todo.source, todo.line))
+
+ prefix = description[:description.find('<<')]
+ suffix = description[description.find('>>') + 2:]
+
+ para = nodes.paragraph(classes=['todo-source'])
+ para += nodes.Text(prefix, prefix)
+
+ # Create a reference
+ linktext = nodes.emphasis(_('original entry'), _('original entry'))
+ reference = nodes.reference('', '', linktext, internal=True)
+ try:
+ reference['refuri'] = self.builder.get_relative_uri(docname, todo['docname'])
+ reference['refuri'] += '#' + todo['ids'][0]
+ except NoUri:
+ # ignore if no URI can be determined, e.g. for LaTeX output
+ pass
+
+ para += reference
+ para += nodes.Text(suffix, suffix)
+
+ return para
+
+
def process_todo_nodes(app, doctree, fromdocname):
# type: (Sphinx, nodes.document, str) -> None
- node = None # type: nodes.Element
- if not app.config['todo_include_todos']:
- for node in doctree.traverse(todo_node):
- node.parent.remove(node)
-
- # Replace all todolist nodes with a list of the collected todos.
- # Augment each todo with a backlink to the original location.
- env = app.builder.env
+ """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)
- if not hasattr(env, 'todo_all_todos'):
- env.todo_all_todos = [] # type: ignore
+ domain = cast(TodoDomain, app.env.get_domain('todo'))
+ todos = sum(domain.todos.values(), [])
for node in doctree.traverse(todolist):
if node.get('ids'):
@@ -146,14 +244,14 @@ def process_todo_nodes(app, doctree, fromdocname):
node.replace_self(content)
continue
- for todo_info in env.todo_all_todos: # type: ignore
+ for todo_info in todos:
para = nodes.paragraph(classes=['todo-source'])
if app.config['todo_link_only']:
description = _('<<original entry>>')
else:
description = (
_('(The <<original entry>> is located in %s, line %d.)') %
- (todo_info['source'], todo_info['lineno'])
+ (todo_info.source, todo_info.line)
)
desc1 = description[:description.find('<<')]
desc2 = description[description.find('>>') + 2:]
@@ -163,17 +261,17 @@ def process_todo_nodes(app, doctree, fromdocname):
innernode = nodes.emphasis(_('original entry'), _('original entry'))
try:
para += make_refnode(app.builder, fromdocname, todo_info['docname'],
- todo_info['target'], innernode)
+ todo_info['ids'][0], innernode)
except NoUri:
# ignore if no URI can be determined, e.g. for LaTeX output
pass
para += nodes.Text(desc2, desc2)
- todo_entry = todo_info['todo']
+ todo_entry = todo_info.deepcopy()
+ todo_entry['ids'].clear()
# (Recursively) resolve references in the todo content
- env.resolve_references(todo_entry, todo_info['docname'],
- app.builder)
+ app.env.resolve_references(todo_entry, todo_info['docname'], app.builder) # type: ignore # NOQA
# Insert into the todolist
content.append(todo_entry)
@@ -184,6 +282,7 @@ def process_todo_nodes(app, doctree, fromdocname):
def purge_todos(app, env, docname):
# type: (Sphinx, BuildEnvironment, str) -> None
+ warnings.warn('purge_todos() is deprecated.', RemovedInSphinx40Warning)
if not hasattr(env, 'todo_all_todos'):
return
env.todo_all_todos = [todo for todo in env.todo_all_todos # type: ignore
@@ -192,6 +291,7 @@ def purge_todos(app, env, docname):
def merge_info(app, env, docnames, other):
# type: (Sphinx, BuildEnvironment, Iterable[str], BuildEnvironment) -> None
+ warnings.warn('merge_info() is deprecated.', RemovedInSphinx40Warning)
if not hasattr(other, 'todo_all_todos'):
return
if not hasattr(env, 'todo_all_todos'):
@@ -201,7 +301,10 @@ def merge_info(app, env, docnames, other):
def visit_todo_node(self, node):
# type: (HTMLTranslator, todo_node) -> None
- self.visit_admonition(node)
+ if self.config.todo_include_todos:
+ self.visit_admonition(node)
+ else:
+ raise nodes.SkipNode
def depart_todo_node(self, node):
@@ -211,11 +314,14 @@ def depart_todo_node(self, node):
def latex_visit_todo_node(self, node):
# type: (LaTeXTranslator, todo_node) -> None
- self.body.append('\n\\begin{sphinxadmonition}{note}{')
- self.body.append(self.hypertarget_to(node))
- title_node = cast(nodes.title, node[0])
- self.body.append('%s:}' % title_node.astext().translate(tex_escape_map))
- node.pop(0)
+ if self.config.todo_include_todos:
+ self.body.append('\n\\begin{sphinxadmonition}{note}{')
+ self.body.append(self.hypertarget_to(node))
+ title_node = cast(nodes.title, node[0])
+ self.body.append('%s:}' % title_node.astext().translate(tex_escape_map))
+ node.pop(0)
+ else:
+ raise nodes.SkipNode
def latex_depart_todo_node(self, node):
@@ -240,12 +346,10 @@ def setup(app):
app.add_directive('todo', Todo)
app.add_directive('todolist', TodoList)
- app.connect('doctree-read', process_todos)
- app.connect('doctree-resolved', process_todo_nodes)
- app.connect('env-purge-doc', purge_todos)
- app.connect('env-merge-info', merge_info)
+ app.add_domain(TodoDomain)
+ app.connect('doctree-resolved', TodoListProcessor)
return {
'version': sphinx.__display_version__,
- 'env_version': 1,
+ 'env_version': 2,
'parallel_read_safe': True
}
diff --git a/sphinx/locale/ar/LC_MESSAGES/sphinx.po b/sphinx/locale/ar/LC_MESSAGES/sphinx.po
index 2452773d1..48df63fc1 100644
--- a/sphinx/locale/ar/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/ar/LC_MESSAGES/sphinx.po
@@ -1448,7 +1448,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/bn/LC_MESSAGES/sphinx.po b/sphinx/locale/bn/LC_MESSAGES/sphinx.po
index 897bc0d6b..89c81694d 100644
--- a/sphinx/locale/bn/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/bn/LC_MESSAGES/sphinx.po
@@ -1448,7 +1448,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/ca/LC_MESSAGES/sphinx.po b/sphinx/locale/ca/LC_MESSAGES/sphinx.po
index 16c5dd220..dcb638253 100644
--- a/sphinx/locale/ca/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/ca/LC_MESSAGES/sphinx.po
@@ -1448,7 +1448,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/cak/LC_MESSAGES/sphinx.po b/sphinx/locale/cak/LC_MESSAGES/sphinx.po
index 0c652d72f..338d62059 100644
--- a/sphinx/locale/cak/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/cak/LC_MESSAGES/sphinx.po
@@ -1448,8 +1448,8 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
-msgstr "\nWe xetz'ib'an ri wuj pa jun ch'abäl man Q'anch' ta,\nyatikïr nacha' jun chïk runuk'unem ch'ab'äl wawe' chi Sphinx tiq'ax\nruch'abäl ri wuj xtik'iyij pa ri ch'ab'äl re.\n\nChi natz'u rucholajem runuk'unem ch'ab'äl k'o chïk pa Sphinx, tab'e pa\nhttp://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
+msgstr "\nWe xetz'ib'an ri wuj pa jun ch'abäl man Q'anch' ta,\nyatikïr nacha' jun chïk runuk'unem ch'ab'äl wawe' chi Sphinx tiq'ax\nruch'abäl ri wuj xtik'iyij pa ri ch'ab'äl re.\n\nChi natz'u rucholajem runuk'unem ch'ab'äl k'o chïk pa Sphinx, tab'e pa\nhttps://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
#: sphinx/cmd/quickstart.py:314
msgid "Project language"
diff --git a/sphinx/locale/cs/LC_MESSAGES/sphinx.po b/sphinx/locale/cs/LC_MESSAGES/sphinx.po
index ed2dbfe76..825dc2166 100644
--- a/sphinx/locale/cs/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/cs/LC_MESSAGES/sphinx.po
@@ -1449,7 +1449,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/cy/LC_MESSAGES/sphinx.po b/sphinx/locale/cy/LC_MESSAGES/sphinx.po
index bc00d3b12..67faadf88 100644
--- a/sphinx/locale/cy/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/cy/LC_MESSAGES/sphinx.po
@@ -1449,7 +1449,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/da/LC_MESSAGES/sphinx.po b/sphinx/locale/da/LC_MESSAGES/sphinx.po
index b7d6f2a4e..721553d0f 100644
--- a/sphinx/locale/da/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/da/LC_MESSAGES/sphinx.po
@@ -1450,7 +1450,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/de/LC_MESSAGES/sphinx.po b/sphinx/locale/de/LC_MESSAGES/sphinx.po
index 96b24539d..cac01042e 100644
--- a/sphinx/locale/de/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/de/LC_MESSAGES/sphinx.po
@@ -1451,7 +1451,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/el/LC_MESSAGES/sphinx.po b/sphinx/locale/el/LC_MESSAGES/sphinx.po
index 2586e7e27..54a19f5fd 100644
--- a/sphinx/locale/el/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/el/LC_MESSAGES/sphinx.po
@@ -1448,7 +1448,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/eo/LC_MESSAGES/sphinx.po b/sphinx/locale/eo/LC_MESSAGES/sphinx.po
index 62b11e910..bd6def59d 100644
--- a/sphinx/locale/eo/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/eo/LC_MESSAGES/sphinx.po
@@ -1448,7 +1448,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/es/LC_MESSAGES/sphinx.po b/sphinx/locale/es/LC_MESSAGES/sphinx.po
index 1b877fdd1..a54f40ef8 100644
--- a/sphinx/locale/es/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/es/LC_MESSAGES/sphinx.po
@@ -1454,8 +1454,8 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
-msgstr "\nSi los documentos están escritos en un idioma distinto al Inglés,\npuedes seleccionar un idioma aqui a través de su código. Sphinx traducirá\nlos textos que genere en dicho idioma.\n\nPara una lista de los códigos soportados visita: \nhttp://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
+msgstr "\nSi los documentos están escritos en un idioma distinto al Inglés,\npuedes seleccionar un idioma aqui a través de su código. Sphinx traducirá\nlos textos que genere en dicho idioma.\n\nPara una lista de los códigos soportados visita: \nhttps://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
#: sphinx/cmd/quickstart.py:314
msgid "Project language"
diff --git a/sphinx/locale/et/LC_MESSAGES/sphinx.po b/sphinx/locale/et/LC_MESSAGES/sphinx.po
index 2237960ae..abc73f875 100644
--- a/sphinx/locale/et/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/et/LC_MESSAGES/sphinx.po
@@ -1451,8 +1451,8 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
-msgstr "\nKui su dokumendid pole kirjutatud inglise keeles, siis võid siin määrata\nkeele vastava keelekoodi abil. Sel juhul tõlgib Sphinx enda genereeritud\nteksti vastavasse keelde.\n\nToetatud keelekoodide kohta vaata\nhttp://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
+msgstr "\nKui su dokumendid pole kirjutatud inglise keeles, siis võid siin määrata\nkeele vastava keelekoodi abil. Sel juhul tõlgib Sphinx enda genereeritud\nteksti vastavasse keelde.\n\nToetatud keelekoodide kohta vaata\nhttps://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
#: sphinx/cmd/quickstart.py:314
msgid "Project language"
diff --git a/sphinx/locale/eu/LC_MESSAGES/sphinx.po b/sphinx/locale/eu/LC_MESSAGES/sphinx.po
index 6ad672fa5..02ac72526 100644
--- a/sphinx/locale/eu/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/eu/LC_MESSAGES/sphinx.po
@@ -1449,7 +1449,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/fa/LC_MESSAGES/sphinx.po b/sphinx/locale/fa/LC_MESSAGES/sphinx.po
index c80f85f81..e9d5a9934 100644
--- a/sphinx/locale/fa/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/fa/LC_MESSAGES/sphinx.po
@@ -1447,7 +1447,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/fi/LC_MESSAGES/sphinx.po b/sphinx/locale/fi/LC_MESSAGES/sphinx.po
index ee28d41a7..d9832746a 100644
--- a/sphinx/locale/fi/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/fi/LC_MESSAGES/sphinx.po
@@ -1448,7 +1448,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/fr/LC_MESSAGES/sphinx.po b/sphinx/locale/fr/LC_MESSAGES/sphinx.po
index 6762dc21e..0516db6d5 100644
--- a/sphinx/locale/fr/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/fr/LC_MESSAGES/sphinx.po
@@ -1465,8 +1465,8 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
-msgstr "\nSi le documents doit être écrit dans une autre langue que l'anglais, vous pouvez choisir une langue ici en saisissant son code. Sphinx traduira le texte qu'il génère dans cette langue. Pour une liste des codes supportés : http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
+msgstr "\nSi le documents doit être écrit dans une autre langue que l'anglais, vous pouvez choisir une langue ici en saisissant son code. Sphinx traduira le texte qu'il génère dans cette langue. Pour une liste des codes supportés : https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
#: sphinx/cmd/quickstart.py:314
msgid "Project language"
diff --git a/sphinx/locale/he/LC_MESSAGES/sphinx.po b/sphinx/locale/he/LC_MESSAGES/sphinx.po
index 2e222d711..7cf0d6e87 100644
--- a/sphinx/locale/he/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/he/LC_MESSAGES/sphinx.po
@@ -1448,7 +1448,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/hi/LC_MESSAGES/sphinx.po b/sphinx/locale/hi/LC_MESSAGES/sphinx.po
index 6a95b6be4..0668fb5b9 100644
--- a/sphinx/locale/hi/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/hi/LC_MESSAGES/sphinx.po
@@ -1449,8 +1449,8 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
-msgstr "\nयदि प्रलेखों को अंग्रेजी के अलावा अन्य किसी भाषा में लिखा जाना है,\nतो यहाँ पर आप भाषा का कूटशब्द दे सकते हैं. स्फिंक्स तदपुरांत,\nजो वाक्यांश बनाता है उसे उस भाषा में अनुवादित करेगा.\n\nमान्य भाषा कूटशब्द सूची यहाँ पर देखें\nhttp://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
+msgstr "\nयदि प्रलेखों को अंग्रेजी के अलावा अन्य किसी भाषा में लिखा जाना है,\nतो यहाँ पर आप भाषा का कूटशब्द दे सकते हैं. स्फिंक्स तदपुरांत,\nजो वाक्यांश बनाता है उसे उस भाषा में अनुवादित करेगा.\n\nमान्य भाषा कूटशब्द सूची यहाँ पर देखें\nhttps://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
#: sphinx/cmd/quickstart.py:314
msgid "Project language"
diff --git a/sphinx/locale/hi_IN/LC_MESSAGES/sphinx.po b/sphinx/locale/hi_IN/LC_MESSAGES/sphinx.po
index 3168863d3..81f7b7cfc 100644
--- a/sphinx/locale/hi_IN/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/hi_IN/LC_MESSAGES/sphinx.po
@@ -1447,7 +1447,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/hr/LC_MESSAGES/sphinx.po b/sphinx/locale/hr/LC_MESSAGES/sphinx.po
index df4eea180..71fa20ac8 100644
--- a/sphinx/locale/hr/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/hr/LC_MESSAGES/sphinx.po
@@ -1448,7 +1448,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/hu/LC_MESSAGES/sphinx.po b/sphinx/locale/hu/LC_MESSAGES/sphinx.po
index 8d172470f..c64a9a59c 100644
--- a/sphinx/locale/hu/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/hu/LC_MESSAGES/sphinx.po
@@ -1452,7 +1452,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/id/LC_MESSAGES/sphinx.po b/sphinx/locale/id/LC_MESSAGES/sphinx.po
index f4ae7cc2c..bd323c2fb 100644
--- a/sphinx/locale/id/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/id/LC_MESSAGES/sphinx.po
@@ -1451,7 +1451,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/it/LC_MESSAGES/sphinx.po b/sphinx/locale/it/LC_MESSAGES/sphinx.po
index baec45df5..19a951be0 100644
--- a/sphinx/locale/it/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/it/LC_MESSAGES/sphinx.po
@@ -1452,7 +1452,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/ja/LC_MESSAGES/sphinx.po b/sphinx/locale/ja/LC_MESSAGES/sphinx.po
index 01a10f634..93f03c07f 100644
--- a/sphinx/locale/ja/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/ja/LC_MESSAGES/sphinx.po
@@ -1460,8 +1460,8 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
-msgstr "\nドキュメントを英語以外の言語で書く場合は、\n 言語コードで言語を選択できます。Sphinx は生成したテキストをその言語に翻訳します。\n\nサポートされているコードのリストについては、\nhttp://sphinx-doc.org/config.html#confval-language を参照してください。"
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
+msgstr "\nドキュメントを英語以外の言語で書く場合は、\n 言語コードで言語を選択できます。Sphinx は生成したテキストをその言語に翻訳します。\n\nサポートされているコードのリストについては、\nhttps://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language を参照してください。"
#: sphinx/cmd/quickstart.py:314
msgid "Project language"
diff --git a/sphinx/locale/ko/LC_MESSAGES/sphinx.po b/sphinx/locale/ko/LC_MESSAGES/sphinx.po
index b88f11d2a..50a7f7448 100644
--- a/sphinx/locale/ko/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/ko/LC_MESSAGES/sphinx.po
@@ -1448,7 +1448,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/lt/LC_MESSAGES/sphinx.po b/sphinx/locale/lt/LC_MESSAGES/sphinx.po
index 9d9707c71..908d02a22 100644
--- a/sphinx/locale/lt/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/lt/LC_MESSAGES/sphinx.po
@@ -1448,7 +1448,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/lv/LC_MESSAGES/sphinx.po b/sphinx/locale/lv/LC_MESSAGES/sphinx.po
index bcfda0332..4b0385fb3 100644
--- a/sphinx/locale/lv/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/lv/LC_MESSAGES/sphinx.po
@@ -1447,7 +1447,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/mk/LC_MESSAGES/sphinx.po b/sphinx/locale/mk/LC_MESSAGES/sphinx.po
index fc4a16386..4a17380ca 100644
--- a/sphinx/locale/mk/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/mk/LC_MESSAGES/sphinx.po
@@ -1448,7 +1448,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/nb_NO/LC_MESSAGES/sphinx.po b/sphinx/locale/nb_NO/LC_MESSAGES/sphinx.po
index 77db4ca5a..53b038c25 100644
--- a/sphinx/locale/nb_NO/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/nb_NO/LC_MESSAGES/sphinx.po
@@ -1447,7 +1447,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/ne/LC_MESSAGES/sphinx.po b/sphinx/locale/ne/LC_MESSAGES/sphinx.po
index e87d8a887..5949d78a9 100644
--- a/sphinx/locale/ne/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/ne/LC_MESSAGES/sphinx.po
@@ -1449,7 +1449,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/nl/LC_MESSAGES/sphinx.po b/sphinx/locale/nl/LC_MESSAGES/sphinx.po
index a52f5ecaa..02b3d2786 100644
--- a/sphinx/locale/nl/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/nl/LC_MESSAGES/sphinx.po
@@ -1453,7 +1453,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/pl/LC_MESSAGES/sphinx.po b/sphinx/locale/pl/LC_MESSAGES/sphinx.po
index 6128a6de6..82903c2de 100644
--- a/sphinx/locale/pl/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/pl/LC_MESSAGES/sphinx.po
@@ -1451,8 +1451,8 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
-msgstr "\nJeśli dokumenty mają być pisane w języku innym niż angielski,\nmożesz tutaj wybrać język przez jego kod. Sphinx następnie\nprzetłumaczy tekst, który generuje, na ten język.\n\nListę wspieranych kodów znajdziesz na\nhttp://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
+msgstr "\nJeśli dokumenty mają być pisane w języku innym niż angielski,\nmożesz tutaj wybrać język przez jego kod. Sphinx następnie\nprzetłumaczy tekst, który generuje, na ten język.\n\nListę wspieranych kodów znajdziesz na\nhttps://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
#: sphinx/cmd/quickstart.py:314
msgid "Project language"
diff --git a/sphinx/locale/pt/LC_MESSAGES/sphinx.po b/sphinx/locale/pt/LC_MESSAGES/sphinx.po
index 058d87dde..47ce06ee0 100644
--- a/sphinx/locale/pt/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/pt/LC_MESSAGES/sphinx.po
@@ -1447,7 +1447,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/pt_BR/LC_MESSAGES/sphinx.po b/sphinx/locale/pt_BR/LC_MESSAGES/sphinx.po
index e54e9288d..4715e32e7 100644
--- a/sphinx/locale/pt_BR/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/pt_BR/LC_MESSAGES/sphinx.po
@@ -1451,7 +1451,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/pt_PT/LC_MESSAGES/sphinx.po b/sphinx/locale/pt_PT/LC_MESSAGES/sphinx.po
index b896e2779..75e9f3135 100644
--- a/sphinx/locale/pt_PT/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/pt_PT/LC_MESSAGES/sphinx.po
@@ -1449,7 +1449,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/ro/LC_MESSAGES/sphinx.po b/sphinx/locale/ro/LC_MESSAGES/sphinx.po
index a0a850740..1ac7ef043 100644
--- a/sphinx/locale/ro/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/ro/LC_MESSAGES/sphinx.po
@@ -1449,7 +1449,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/ru/LC_MESSAGES/sphinx.po b/sphinx/locale/ru/LC_MESSAGES/sphinx.po
index 4ccab39b5..f9cdfba3a 100644
--- a/sphinx/locale/ru/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/ru/LC_MESSAGES/sphinx.po
@@ -1453,7 +1453,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/si/LC_MESSAGES/sphinx.po b/sphinx/locale/si/LC_MESSAGES/sphinx.po
index 5852306a2..59e13eaed 100644
--- a/sphinx/locale/si/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/si/LC_MESSAGES/sphinx.po
@@ -1448,7 +1448,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/sk/LC_MESSAGES/sphinx.po b/sphinx/locale/sk/LC_MESSAGES/sphinx.po
index 70275b891..90213cf37 100644
--- a/sphinx/locale/sk/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/sk/LC_MESSAGES/sphinx.po
@@ -1450,7 +1450,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/sl/LC_MESSAGES/sphinx.po b/sphinx/locale/sl/LC_MESSAGES/sphinx.po
index 0353526c0..3d94d0f54 100644
--- a/sphinx/locale/sl/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/sl/LC_MESSAGES/sphinx.po
@@ -1447,7 +1447,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/sphinx.pot b/sphinx/locale/sphinx.pot
index 07f4216c4..c4f9a54fb 100644
--- a/sphinx/locale/sphinx.pot
+++ b/sphinx/locale/sphinx.pot
@@ -1461,7 +1461,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/sr/LC_MESSAGES/sphinx.po b/sphinx/locale/sr/LC_MESSAGES/sphinx.po
index e13bb82d9..1e99514a3 100644
--- a/sphinx/locale/sr/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/sr/LC_MESSAGES/sphinx.po
@@ -1448,7 +1448,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/sr@latin/LC_MESSAGES/sphinx.po b/sphinx/locale/sr@latin/LC_MESSAGES/sphinx.po
index 941497ee1..0fe6b5ca7 100644
--- a/sphinx/locale/sr@latin/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/sr@latin/LC_MESSAGES/sphinx.po
@@ -1447,7 +1447,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/sr_RS/LC_MESSAGES/sphinx.po b/sphinx/locale/sr_RS/LC_MESSAGES/sphinx.po
index 3e78b6f2b..8c95c6cd9 100644
--- a/sphinx/locale/sr_RS/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/sr_RS/LC_MESSAGES/sphinx.po
@@ -1447,7 +1447,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/sv/LC_MESSAGES/sphinx.po b/sphinx/locale/sv/LC_MESSAGES/sphinx.po
index 8f26be6f1..d6004ba71 100644
--- a/sphinx/locale/sv/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/sv/LC_MESSAGES/sphinx.po
@@ -1447,7 +1447,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/ta/LC_MESSAGES/sphinx.po b/sphinx/locale/ta/LC_MESSAGES/sphinx.po
index 9d42b0728..ef9ac7d92 100644
--- a/sphinx/locale/ta/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/ta/LC_MESSAGES/sphinx.po
@@ -1448,7 +1448,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/tr/LC_MESSAGES/sphinx.po b/sphinx/locale/tr/LC_MESSAGES/sphinx.po
index 4c1f310c4..c6dac42b8 100644
--- a/sphinx/locale/tr/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/tr/LC_MESSAGES/sphinx.po
@@ -1449,7 +1449,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/uk_UA/LC_MESSAGES/sphinx.po b/sphinx/locale/uk_UA/LC_MESSAGES/sphinx.po
index 9506624c0..fd08c96bf 100644
--- a/sphinx/locale/uk_UA/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/uk_UA/LC_MESSAGES/sphinx.po
@@ -1448,7 +1448,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/ur/LC_MESSAGES/sphinx.po b/sphinx/locale/ur/LC_MESSAGES/sphinx.po
index 1464969b7..975cd09ca 100644
--- a/sphinx/locale/ur/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/ur/LC_MESSAGES/sphinx.po
@@ -1447,7 +1447,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/vi/LC_MESSAGES/sphinx.po b/sphinx/locale/vi/LC_MESSAGES/sphinx.po
index 01bae6d8c..f2e3e766b 100644
--- a/sphinx/locale/vi/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/vi/LC_MESSAGES/sphinx.po
@@ -1448,7 +1448,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/locale/zh_CN/LC_MESSAGES/sphinx.po b/sphinx/locale/zh_CN/LC_MESSAGES/sphinx.po
index a5c28080b..72429ac95 100644
--- a/sphinx/locale/zh_CN/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/zh_CN/LC_MESSAGES/sphinx.po
@@ -1456,8 +1456,8 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
-msgstr "\n如果用英语以外的语言编写文档,你可以在此按语言代码选择语种。\nSphinx 会把内置文本翻译成相应语言的版本。\n\n支持的语言代码列表见:\nhttp://sphinx-doc.org/config.html#confval-language。"
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
+msgstr "\n如果用英语以外的语言编写文档,你可以在此按语言代码选择语种。\nSphinx 会把内置文本翻译成相应语言的版本。\n\n支持的语言代码列表见:\nhttps://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language。"
#: sphinx/cmd/quickstart.py:314
msgid "Project language"
diff --git a/sphinx/locale/zh_TW/LC_MESSAGES/sphinx.po b/sphinx/locale/zh_TW/LC_MESSAGES/sphinx.po
index cafadd80a..ebe07553b 100644
--- a/sphinx/locale/zh_TW/LC_MESSAGES/sphinx.po
+++ b/sphinx/locale/zh_TW/LC_MESSAGES/sphinx.po
@@ -1453,7 +1453,7 @@ msgid ""
"translate text that it generates into that language.\n"
"\n"
"For a list of supported codes, see\n"
-"http://sphinx-doc.org/config.html#confval-language."
+"https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language."
msgstr ""
#: sphinx/cmd/quickstart.py:314
diff --git a/sphinx/pycode/parser.py b/sphinx/pycode/parser.py
index f9489e91a..1746537bb 100644
--- a/sphinx/pycode/parser.py
+++ b/sphinx/pycode/parser.py
@@ -357,6 +357,17 @@ class VariableCommentPicker(ast.NodeVisitor):
except TypeError:
pass # this assignment is not new definition!
+ def visit_Try(self, node):
+ # type: (ast.Try) -> None
+ """Handles Try node and processes body and else-clause.
+
+ .. note:: pycode parser ignores objects definition in except-clause.
+ """
+ for subnode in node.body:
+ self.visit(subnode)
+ for subnode in node.orelse:
+ self.visit(subnode)
+
def visit_ClassDef(self, node):
# type: (ast.ClassDef) -> None
"""Handles ClassDef node and set context."""
diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py
index 9f01a9f9f..25010c41f 100644
--- a/sphinx/util/docutils.py
+++ b/sphinx/util/docutils.py
@@ -15,7 +15,7 @@ from copy import copy
from distutils.version import LooseVersion
from os import path
from types import ModuleType
-from typing import Any, Callable, Dict, Generator, IO, List, Set, Tuple, Type
+from typing import Any, Callable, Dict, Generator, IO, List, Optional, Set, Tuple, Type
from typing import cast
import docutils
@@ -184,14 +184,14 @@ class sphinx_domains:
def __exit__(self, exc_type: Type[Exception], exc_value: Exception, traceback: Any) -> bool: # NOQA
self.disable()
- return True
+ return False
def enable(self) -> None:
self.directive_func = directives.directive
self.role_func = roles.role
- directives.directive = self.lookup_directive # type: ignore
- roles.role = self.lookup_role # type: ignore
+ directives.directive = self.lookup_directive
+ roles.role = self.lookup_role
def disable(self) -> None:
directives.directive = self.directive_func
@@ -225,17 +225,17 @@ class sphinx_domains:
raise ElementLookupError
- def lookup_directive(self, name: str, lang_module: ModuleType, document: nodes.document) -> Tuple[Type[Directive], List[system_message]]: # NOQA
+ def lookup_directive(self, directive_name: str, language_module: ModuleType, document: nodes.document) -> Tuple[Optional[Type[Directive]], List[system_message]]: # NOQA
try:
- return self.lookup_domain_element('directive', name)
+ return self.lookup_domain_element('directive', directive_name)
except ElementLookupError:
- return self.directive_func(name, lang_module, document)
+ return self.directive_func(directive_name, language_module, document)
- def lookup_role(self, name: str, lang_module: ModuleType, lineno: int, reporter: Reporter) -> Tuple[RoleFunction, List[system_message]]: # NOQA
+ def lookup_role(self, role_name: str, language_module: ModuleType, lineno: int, reporter: Reporter) -> Tuple[RoleFunction, List[system_message]]: # NOQA
try:
- return self.lookup_domain_element('role', name)
+ return self.lookup_domain_element('role', role_name)
except ElementLookupError:
- return self.role_func(name, lang_module, lineno, reporter)
+ return self.role_func(role_name, language_module, lineno, reporter)
class WarningStream:
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py
index 77724d38b..67f396e73 100644
--- a/sphinx/util/typing.py
+++ b/sphinx/util/typing.py
@@ -27,7 +27,7 @@ NoneType = type(None)
PathMatcher = Callable[[str], bool]
# common role functions
-RoleFunction = Callable[[str, str, str, int, Inliner, Dict, List[str]],
+RoleFunction = Callable[[str, str, str, int, Inliner, Dict[str, Any], List[str]],
Tuple[List[nodes.Node], List[nodes.system_message]]]
# title getter functions for enumerable nodes (see sphinx.domains.std)
diff --git a/tests/roots/test-ext-autodoc/target/module.py b/tests/roots/test-ext-autodoc/target/module.py
deleted file mode 100644
index d5b557d94..000000000
--- a/tests/roots/test-ext-autodoc/target/module.py
+++ /dev/null
@@ -1,4 +0,0 @@
-#: docstring for CONSTANT1
-CONSTANT1 = ""
-
-CONSTANT2 = ""
diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py
index 98f8f1a99..5cad89cdf 100644
--- a/tests/test_autodoc.py
+++ b/tests/test_autodoc.py
@@ -1347,30 +1347,6 @@ def test_partialmethod(app):
assert list(actual) == expected
-@pytest.mark.usefixtures('setup_test')
-def test_module_variables():
- options = {"members": None,
- "undoc-members": True}
- actual = do_autodoc(app, 'module', 'target.module', options)
- assert list(actual) == [
- '',
- '.. py:module:: target.module',
- '',
- '',
- '.. py:data:: CONSTANT1',
- ' :module: target.module',
- " :annotation: = ''",
- '',
- ' docstring for CONSTANT1',
- ' ',
- '',
- '.. py:data:: CONSTANT2',
- ' :module: target.module',
- " :annotation: = ''",
- '',
- ]
-
-
@pytest.mark.sphinx('html', testroot='pycode-egg')
def test_autodoc_for_egged_code(app):
options = {"members": None,
diff --git a/tests/test_ext_napoleon_docstring.py b/tests/test_ext_napoleon_docstring.py
index a333dc47b..f1714bd62 100644
--- a/tests/test_ext_napoleon_docstring.py
+++ b/tests/test_ext_napoleon_docstring.py
@@ -1351,8 +1351,8 @@ arg_ : type
"""
expected = """
-:ivar arg_: some description
-:vartype arg_: type
+:ivar arg\\_: some description
+:vartype arg\\_: type
"""
config = Config(napoleon_use_ivar=True)
diff --git a/tests/test_pycode_parser.py b/tests/test_pycode_parser.py
index ba9778b80..8f8c6cbab 100644
--- a/tests/test_pycode_parser.py
+++ b/tests/test_pycode_parser.py
@@ -149,6 +149,21 @@ def test_complex_assignment_py3():
assert parser.definitions == {}
+def test_assignment_in_try_clause():
+ source = ('try:\n'
+ ' a = None #: comment\n'
+ 'except:\n'
+ ' b = None #: ignored\n'
+ 'else:\n'
+ ' c = None #: comment\n')
+ parser = Parser(source)
+ parser.parse()
+ assert parser.comments == {('', 'a'): 'comment',
+ ('', 'c'): 'comment'}
+ assert parser.deforders == {'a': 0,
+ 'c': 1}
+
+
def test_obj_assignment():
source = ('obj = SomeObject() #: some object\n'
'obj.attr = 1 #: attr1\n'