summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-01-01 11:39:46 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-01-01 11:39:46 +0900
commite628afd5cd0c565f1e33abb01cac26180455182f (patch)
tree3b7cddfe175c444588a0b8d9e80430faeb994b8c
parent9458d631d0393956005754ed8137809e15635467 (diff)
parentc5b653433d3fbdca47396f17161685f50d994320 (diff)
downloadsphinx-git-e628afd5cd0c565f1e33abb01cac26180455182f.tar.gz
Merge branch '2.0'
-rw-r--r--CHANGES10
-rw-r--r--doc/extdev/deprecated.rst30
-rw-r--r--doc/usage/extensions/graphviz.rst21
-rw-r--r--setup.cfg1
-rw-r--r--sphinx/__init__.py2
-rw-r--r--sphinx/__main__.py2
-rw-r--r--sphinx/addnodes.py6
-rw-r--r--sphinx/application.py15
-rw-r--r--sphinx/builders/__init__.py6
-rw-r--r--sphinx/builders/_epub_base.py2
-rw-r--r--sphinx/builders/applehelp.py2
-rw-r--r--sphinx/builders/changes.py4
-rw-r--r--sphinx/builders/devhelp.py2
-rw-r--r--sphinx/builders/dirhtml.py2
-rw-r--r--sphinx/builders/gettext.py6
-rw-r--r--sphinx/builders/html.py4
-rw-r--r--sphinx/builders/htmlhelp.py2
-rw-r--r--sphinx/builders/latex/__init__.py4
-rw-r--r--sphinx/builders/latex/nodes.py2
-rw-r--r--sphinx/builders/latex/transforms.py18
-rw-r--r--sphinx/builders/linkcheck.py2
-rw-r--r--sphinx/builders/manpage.py4
-rw-r--r--sphinx/builders/qthelp.py2
-rw-r--r--sphinx/builders/singlehtml.py6
-rw-r--r--sphinx/builders/texinfo.py4
-rw-r--r--sphinx/builders/text.py2
-rw-r--r--sphinx/builders/xml.py2
-rw-r--r--sphinx/cmd/__init__.py2
-rw-r--r--sphinx/cmd/build.py2
-rw-r--r--sphinx/cmd/make_mode.py2
-rw-r--r--sphinx/cmd/quickstart.py2
-rw-r--r--sphinx/config.py2
-rw-r--r--sphinx/deprecation.py2
-rw-r--r--sphinx/directives/__init__.py7
-rw-r--r--sphinx/directives/code.py2
-rw-r--r--sphinx/directives/other.py40
-rw-r--r--sphinx/directives/patches.py2
-rw-r--r--sphinx/domains/__init__.py4
-rw-r--r--sphinx/domains/c.py2
-rw-r--r--sphinx/domains/changeset.py2
-rw-r--r--sphinx/domains/citation.py6
-rw-r--r--sphinx/domains/cpp.py1557
-rw-r--r--sphinx/domains/index.py63
-rw-r--r--sphinx/domains/javascript.py2
-rw-r--r--sphinx/domains/math.py2
-rw-r--r--sphinx/domains/python.py2
-rw-r--r--sphinx/domains/rst.py2
-rw-r--r--sphinx/domains/std.py4
-rw-r--r--sphinx/environment/__init__.py2
-rw-r--r--sphinx/environment/adapters/__init__.py2
-rw-r--r--sphinx/environment/adapters/asset.py2
-rw-r--r--sphinx/environment/adapters/indexentries.py2
-rw-r--r--sphinx/environment/adapters/toctree.py8
-rw-r--r--sphinx/environment/collectors/__init__.py2
-rw-r--r--sphinx/environment/collectors/asset.py2
-rw-r--r--sphinx/environment/collectors/dependencies.py2
-rw-r--r--sphinx/environment/collectors/indexentries.py2
-rw-r--r--sphinx/environment/collectors/metadata.py2
-rw-r--r--sphinx/environment/collectors/title.py2
-rw-r--r--sphinx/environment/collectors/toctree.py2
-rw-r--r--sphinx/errors.py2
-rw-r--r--sphinx/events.py6
-rw-r--r--sphinx/ext/__init__.py2
-rw-r--r--sphinx/ext/apidoc.py2
-rw-r--r--sphinx/ext/autodoc/__init__.py28
-rw-r--r--sphinx/ext/autodoc/importer.py2
-rw-r--r--sphinx/ext/autodoc/mock.py8
-rw-r--r--sphinx/ext/autosectionlabel.py2
-rw-r--r--sphinx/ext/autosummary/__init__.py2
-rw-r--r--sphinx/ext/autosummary/generate.py4
-rw-r--r--sphinx/ext/coverage.py4
-rw-r--r--sphinx/ext/doctest.py2
-rw-r--r--sphinx/ext/duration.py6
-rw-r--r--sphinx/ext/extlinks.py2
-rw-r--r--sphinx/ext/githubpages.py2
-rw-r--r--sphinx/ext/graphviz.py14
-rw-r--r--sphinx/ext/ifconfig.py2
-rw-r--r--sphinx/ext/imgconverter.py2
-rw-r--r--sphinx/ext/imgmath.py2
-rw-r--r--sphinx/ext/inheritance_diagram.py2
-rw-r--r--sphinx/ext/intersphinx.py2
-rw-r--r--sphinx/ext/jsmath.py2
-rw-r--r--sphinx/ext/linkcode.py2
-rw-r--r--sphinx/ext/mathjax.py2
-rw-r--r--sphinx/ext/napoleon/__init__.py4
-rw-r--r--sphinx/ext/napoleon/docstring.py2
-rw-r--r--sphinx/ext/napoleon/iterators.py6
-rw-r--r--sphinx/ext/todo.py2
-rw-r--r--sphinx/ext/viewcode.py2
-rw-r--r--sphinx/extension.py4
-rw-r--r--sphinx/highlighting.py6
-rw-r--r--sphinx/io.py8
-rw-r--r--sphinx/jinja2glue.py4
-rw-r--r--sphinx/locale/__init__.py2
-rw-r--r--sphinx/parsers.py2
-rw-r--r--sphinx/project.py2
-rw-r--r--sphinx/pycode/__init__.py87
-rw-r--r--sphinx/pycode/parser.py4
-rw-r--r--sphinx/pygments_styles.py2
-rw-r--r--sphinx/registry.py9
-rw-r--r--sphinx/roles.py4
-rw-r--r--sphinx/search/__init__.py2
-rw-r--r--sphinx/search/en.py2
-rw-r--r--sphinx/search/ja.py2
-rw-r--r--sphinx/search/jssplitter.py2
-rw-r--r--sphinx/search/zh.py2
-rw-r--r--sphinx/setup_command.py2
-rw-r--r--sphinx/templates/graphviz/graphviz.css2
-rw-r--r--sphinx/testing/__init__.py2
-rw-r--r--sphinx/testing/comparer.py2
-rw-r--r--sphinx/testing/fixtures.py2
-rw-r--r--sphinx/testing/path.py10
-rw-r--r--sphinx/testing/restructuredtext.py2
-rw-r--r--sphinx/testing/util.py8
-rw-r--r--sphinx/themes/agogo/layout.html2
-rw-r--r--sphinx/themes/agogo/static/agogo.css_t2
-rw-r--r--sphinx/themes/basic/defindex.html2
-rw-r--r--sphinx/themes/basic/domainindex.html2
-rw-r--r--sphinx/themes/basic/genindex-single.html2
-rw-r--r--sphinx/themes/basic/genindex-split.html2
-rw-r--r--sphinx/themes/basic/genindex.html2
-rw-r--r--sphinx/themes/basic/globaltoc.html2
-rw-r--r--sphinx/themes/basic/layout.html2
-rw-r--r--sphinx/themes/basic/localtoc.html2
-rw-r--r--sphinx/themes/basic/page.html2
-rw-r--r--sphinx/themes/basic/relations.html2
-rw-r--r--sphinx/themes/basic/search.html2
-rw-r--r--sphinx/themes/basic/searchbox.html2
-rw-r--r--sphinx/themes/basic/searchresults.html2
-rw-r--r--sphinx/themes/basic/sourcelink.html2
-rw-r--r--sphinx/themes/basic/static/basic.css_t2
-rw-r--r--sphinx/themes/basic/static/doctools.js2
-rw-r--r--sphinx/themes/basic/static/language_data.js_t2
-rw-r--r--sphinx/themes/basic/static/searchtools.js2
-rw-r--r--sphinx/themes/classic/layout.html2
-rw-r--r--sphinx/themes/classic/static/classic.css_t2
-rw-r--r--sphinx/themes/classic/static/sidebar.js_t2
-rw-r--r--sphinx/themes/epub/epub-cover.html2
-rw-r--r--sphinx/themes/epub/layout.html2
-rw-r--r--sphinx/themes/epub/static/epub.css_t2
-rw-r--r--sphinx/themes/haiku/layout.html2
-rw-r--r--sphinx/themes/haiku/static/haiku.css_t2
-rw-r--r--sphinx/themes/nature/static/nature.css_t2
-rw-r--r--sphinx/themes/nonav/layout.html2
-rw-r--r--sphinx/themes/nonav/static/nonav.css2
-rw-r--r--sphinx/themes/pyramid/static/epub.css2
-rw-r--r--sphinx/themes/pyramid/static/pyramid.css_t2
-rw-r--r--sphinx/themes/scrolls/layout.html2
-rw-r--r--sphinx/themes/scrolls/static/scrolls.css_t2
-rw-r--r--sphinx/themes/sphinxdoc/layout.html2
-rw-r--r--sphinx/themes/sphinxdoc/static/sphinxdoc.css_t2
-rw-r--r--sphinx/themes/traditional/static/traditional.css_t2
-rw-r--r--sphinx/theming.py2
-rw-r--r--sphinx/transforms/__init__.py32
-rw-r--r--sphinx/transforms/compact_bullet_list.py4
-rw-r--r--sphinx/transforms/i18n.py8
-rw-r--r--sphinx/transforms/post_transforms/__init__.py10
-rw-r--r--sphinx/transforms/post_transforms/code.py6
-rw-r--r--sphinx/transforms/post_transforms/images.py4
-rw-r--r--sphinx/transforms/references.py8
-rw-r--r--sphinx/util/__init__.py8
-rw-r--r--sphinx/util/build_phase.py2
-rw-r--r--sphinx/util/compat.py4
-rw-r--r--sphinx/util/console.py2
-rw-r--r--sphinx/util/docfields.py2
-rw-r--r--sphinx/util/docstrings.py2
-rw-r--r--sphinx/util/docutils.py4
-rw-r--r--sphinx/util/fileutil.py2
-rw-r--r--sphinx/util/i18n.py2
-rw-r--r--sphinx/util/images.py2
-rw-r--r--sphinx/util/inspect.py4
-rw-r--r--sphinx/util/inventory.py2
-rw-r--r--sphinx/util/jsdump.py2
-rw-r--r--sphinx/util/jsonimpl.py10
-rw-r--r--sphinx/util/logging.py6
-rw-r--r--sphinx/util/matching.py2
-rw-r--r--sphinx/util/math.py2
-rw-r--r--sphinx/util/nodes.py4
-rw-r--r--sphinx/util/osutil.py2
-rw-r--r--sphinx/util/parallel.py2
-rw-r--r--sphinx/util/png.py2
-rw-r--r--sphinx/util/pycompat.py2
-rw-r--r--sphinx/util/requests.py10
-rw-r--r--sphinx/util/rst.py2
-rw-r--r--sphinx/util/stemmer/__init__.py2
-rw-r--r--sphinx/util/tags.py2
-rw-r--r--sphinx/util/template.py2
-rw-r--r--sphinx/util/texescape.py2
-rw-r--r--sphinx/util/typing.py2
-rw-r--r--sphinx/versioning.py4
-rw-r--r--sphinx/writers/__init__.py2
-rw-r--r--sphinx/writers/html.py6
-rw-r--r--sphinx/writers/html5.py6
-rw-r--r--sphinx/writers/latex.py2
-rw-r--r--sphinx/writers/manpage.py6
-rw-r--r--sphinx/writers/texinfo.py6
-rw-r--r--sphinx/writers/text.py6
-rw-r--r--sphinx/writers/xml.py6
-rw-r--r--tests/roots/test-ext-graphviz/index.rst3
-rw-r--r--tests/roots/test-pycode/cp_1251_coded.py4
-rw-r--r--tests/test_environment_indexentries.py18
-rw-r--r--tests/test_ext_graphviz.py5
-rw-r--r--tests/test_pycode.py25
203 files changed, 1167 insertions, 1370 deletions
diff --git a/CHANGES b/CHANGES
index df590535e..e6d1944ba 100644
--- a/CHANGES
+++ b/CHANGES
@@ -50,10 +50,16 @@ Incompatible changes
Deprecated
----------
+* The ``decode`` argument of ``sphinx.pycode.ModuleAnalyzer()``
+* ``sphinx.directives.other.Index``
* ``sphinx.environment.BuildEnvironment.indexentries``
* ``sphinx.environment.collectors.indexentries.IndexEntriesCollector``
* ``sphinx.io.FiletypeNotFoundError``
* ``sphinx.io.get_filetype()``
+* ``sphinx.pycode.ModuleAnalyzer.encoding``
+* ``sphinx.roles.Index``
+* ``sphinx.util.detect_encoding()``
+* ``sphinx.util.get_module_source()``
Features added
--------------
@@ -62,12 +68,14 @@ Features added
* #6446: duration: Add ``sphinx.ext.durations`` to inspect which documents slow
down the build
* #6837: LaTeX: Support a nested table
+* #6966: graphviz: Support ``:class:`` option
Bugs fixed
----------
* #6925: html: Remove redundant type="text/javascript" from <script> elements
-* #6906: autodoc: failed to read the source codes encoeded in cp1251
+* #6906, #6907: autodoc: failed to read the source codes encoeded in cp1251
+* #6961: latex: warning for babel shown twice
Testing
--------
diff --git a/doc/extdev/deprecated.rst b/doc/extdev/deprecated.rst
index 52dcddfdb..3deac657d 100644
--- a/doc/extdev/deprecated.rst
+++ b/doc/extdev/deprecated.rst
@@ -31,6 +31,16 @@ The following is a list of deprecated interfaces.
- 5.0
- ``sphinx.domains.std.StandardDomain.note_object()``
+ * - ``decode`` argument of ``sphinx.pycode.ModuleAnalyzer()``
+ - 2.4
+ - 4.0
+ - N/A
+
+ * - ``sphinx.directives.other.Index``
+ - 2.4
+ - 4.0
+ - ``sphinx.domains.index.IndexDirective``
+
* - ``sphinx.environment.BuildEnvironment.indexentries``
- 2.4
- 4.0
@@ -51,6 +61,26 @@ The following is a list of deprecated interfaces.
- 4.0
- ``sphinx.util.get_filetype()``
+ * - ``sphinx.pycode.ModuleAnalyzer.encoding``
+ - 2.4
+ - 4.0
+ - N/A
+
+ * - ``sphinx.roles.Index``
+ - 2.4
+ - 4.0
+ - ``sphinx.domains.index.IndexRole``
+
+ * - ``sphinx.util.detect_encoding()``
+ - 2.4
+ - 4.0
+ - ``tokenize.detect_encoding()``
+
+ * - ``sphinx.util.get_module_source()``
+ - 2.4
+ - 4.0
+ - N/A
+
* - ``sphinx.builders.gettext.POHEADER``
- 2.3
- 4.0
diff --git a/doc/usage/extensions/graphviz.rst b/doc/usage/extensions/graphviz.rst
index dd21b8214..32cfcce30 100644
--- a/doc/usage/extensions/graphviz.rst
+++ b/doc/usage/extensions/graphviz.rst
@@ -82,6 +82,13 @@ It adds these directives:
.. versionadded:: 1.6
+ .. rst:directive:option:: class: class names
+ :type: a list of class names separeted by spaces
+
+ The class name of the graph.
+
+ .. versionadded:: 2.4
+
.. rst:directive:: graph
@@ -131,6 +138,13 @@ It adds these directives:
.. versionadded:: 1.6
+ .. rst:directive:option:: class: class names
+ :type: a list of class names separeted by spaces
+
+ The class name of the graph.
+
+ .. versionadded:: 2.4
+
.. rst:directive:: digraph
@@ -176,6 +190,13 @@ It adds these directives:
.. versionadded:: 1.6
+ .. rst:directive:option:: class: class names
+ :type: a list of class names separeted by spaces
+
+ The class name of the graph.
+
+ .. versionadded:: 2.4
+
There are also these config values:
diff --git a/setup.cfg b/setup.cfg
index e4d577f93..8aa9f30ff 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -41,6 +41,7 @@ paths =
[mypy]
python_version = 3.5
+disallow_incomplete_defs = True
show_column_numbers = True
show_error_context = True
ignore_missing_imports = True
diff --git a/sphinx/__init__.py b/sphinx/__init__.py
index 690e0d71f..4889f35d5 100644
--- a/sphinx/__init__.py
+++ b/sphinx/__init__.py
@@ -4,7 +4,7 @@
The Sphinx documentation toolchain.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/__main__.py b/sphinx/__main__.py
index 22ea029b0..5da409015 100644
--- a/sphinx/__main__.py
+++ b/sphinx/__main__.py
@@ -4,7 +4,7 @@
The Sphinx documentation toolchain.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/addnodes.py b/sphinx/addnodes.py
index 7b1edc018..15d5fc46b 100644
--- a/sphinx/addnodes.py
+++ b/sphinx/addnodes.py
@@ -4,7 +4,7 @@
Additional docutils nodes.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -12,6 +12,7 @@ import warnings
from typing import Any, Dict, List, Sequence
from docutils import nodes
+from docutils.nodes import Node
from sphinx.deprecation import RemovedInSphinx40Warning
@@ -305,7 +306,8 @@ class abbreviation(nodes.abbreviation):
.. deprecated:: 2.0
"""
- def __init__(self, rawsource: str = '', text: str = '', *children, **attributes) -> None:
+ def __init__(self, rawsource: str = '', text: str = '',
+ *children: Node, **attributes: Any) -> None:
warnings.warn("abbrevition node for Sphinx was replaced by docutils'.",
RemovedInSphinx40Warning, stacklevel=2)
diff --git a/sphinx/application.py b/sphinx/application.py
index ba4b6996f..4797c9583 100644
--- a/sphinx/application.py
+++ b/sphinx/application.py
@@ -6,7 +6,7 @@
Gracefully adapted from the TextPress system by Armin.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -422,7 +422,7 @@ class Sphinx:
logger.debug('[app] disconnecting event: [id=%s]', listener_id)
self.events.disconnect(listener_id)
- def emit(self, event: str, *args) -> List:
+ def emit(self, event: str, *args: Any) -> List:
"""Emit *event* and pass *arguments* to the callback functions.
Return the return values of all callbacks as a list. Do not emit core
@@ -430,7 +430,7 @@ class Sphinx:
"""
return self.events.emit(event, *args)
- def emit_firstresult(self, event: str, *args) -> Any:
+ def emit_firstresult(self, event: str, *args: Any) -> Any:
"""Emit *event* and pass *arguments* to the callback functions.
Return the result of the first callback that doesn't return ``None``.
@@ -508,7 +508,8 @@ class Sphinx:
"""
self.registry.add_translator(name, translator_class, override=override)
- def add_node(self, node: "Type[Element]", override: bool = False, **kwds) -> None:
+ def add_node(self, node: "Type[Element]", override: bool = False,
+ **kwds: Tuple[Callable, Callable]) -> None:
"""Register a Docutils node class.
This is necessary for Docutils internals. It may also be used in the
@@ -548,7 +549,7 @@ class Sphinx:
def add_enumerable_node(self, node: "Type[Element]", figtype: str,
title_getter: TitleGetter = None, override: bool = False,
- **kwds) -> None:
+ **kwds: Tuple[Callable, Callable]) -> None:
"""Register a Docutils node class as a numfig target.
Sphinx numbers the node automatically. And then the users can refer it
@@ -575,7 +576,7 @@ class Sphinx:
self.registry.add_enumerable_node(node, figtype, title_getter, override=override)
self.add_node(node, override=override, **kwds)
- def add_directive(self, name: str, cls: "Type[Directive]", override: bool = False):
+ def add_directive(self, name: str, cls: "Type[Directive]", override: bool = False) -> None:
"""Register a Docutils directive.
*name* must be the prospective directive name. *cls* is a directive
@@ -1036,7 +1037,7 @@ class Sphinx:
"""
self.registry.add_source_suffix(suffix, filetype, override=override)
- def add_source_parser(self, *args, **kwargs) -> None:
+ def add_source_parser(self, *args: Any, **kwargs: Any) -> None:
"""Register a parser class.
.. versionadded:: 1.4
diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py
index 777536d3e..c596df3c5 100644
--- a/sphinx/builders/__init__.py
+++ b/sphinx/builders/__init__.py
@@ -4,7 +4,7 @@
Builder superclass for all builders.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -118,11 +118,11 @@ class Builder:
self.env.set_versioning_method(self.versioning_method,
self.versioning_compare)
- def get_translator_class(self, *args) -> "Type[nodes.NodeVisitor]":
+ def get_translator_class(self, *args: Any) -> "Type[nodes.NodeVisitor]":
"""Return a class of translator."""
return self.app.registry.get_translator_class(self)
- def create_translator(self, *args) -> nodes.NodeVisitor:
+ def create_translator(self, *args: Any) -> nodes.NodeVisitor:
"""Return an instance of translator.
This method returns an instance of ``default_translator_class`` by default.
diff --git a/sphinx/builders/_epub_base.py b/sphinx/builders/_epub_base.py
index 9bdf856a6..f86715fcf 100644
--- a/sphinx/builders/_epub_base.py
+++ b/sphinx/builders/_epub_base.py
@@ -4,7 +4,7 @@
Base class of epub2/epub3 builders.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/builders/applehelp.py b/sphinx/builders/applehelp.py
index d7dd336ca..f081f9fe5 100644
--- a/sphinx/builders/applehelp.py
+++ b/sphinx/builders/applehelp.py
@@ -4,7 +4,7 @@
Build Apple help books.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/builders/changes.py b/sphinx/builders/changes.py
index a42215fad..7cf9d098b 100644
--- a/sphinx/builders/changes.py
+++ b/sphinx/builders/changes.py
@@ -4,7 +4,7 @@
Changelog builder.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -50,7 +50,7 @@ class ChangesBuilder(Builder):
'deprecated': 'deprecated',
}
- def write(self, *ignored) -> None:
+ def write(self, *ignored: Any) -> None:
version = self.config.version
domain = cast(ChangeSetDomain, self.env.get_domain('changeset'))
libchanges = {} # type: Dict[str, List[Tuple[str, str, int]]]
diff --git a/sphinx/builders/devhelp.py b/sphinx/builders/devhelp.py
index 17e861777..dda7c411f 100644
--- a/sphinx/builders/devhelp.py
+++ b/sphinx/builders/devhelp.py
@@ -6,7 +6,7 @@
.. _Devhelp: https://wiki.gnome.org/Apps/Devhelp
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/builders/dirhtml.py b/sphinx/builders/dirhtml.py
index 25c999003..ba60c923c 100644
--- a/sphinx/builders/dirhtml.py
+++ b/sphinx/builders/dirhtml.py
@@ -4,7 +4,7 @@
Directory HTML builders.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/builders/gettext.py b/sphinx/builders/gettext.py
index e7adb0b8c..f5264837c 100644
--- a/sphinx/builders/gettext.py
+++ b/sphinx/builders/gettext.py
@@ -4,7 +4,7 @@
The MessageCatalogBuilder class.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -198,7 +198,7 @@ if source_date_epoch is not None:
class LocalTimeZone(tzinfo):
- def __init__(self, *args, **kw) -> None:
+ def __init__(self, *args: Any, **kw: Any) -> None:
super().__init__(*args, **kw) # type: ignore
self.tzdelta = tzdelta
@@ -212,7 +212,7 @@ class LocalTimeZone(tzinfo):
ltz = LocalTimeZone()
-def should_write(filepath: str, new_content: str):
+def should_write(filepath: str, new_content: str) -> bool:
if not path.exists(filepath):
return True
try:
diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py
index 7257b32ef..f76cf5ce5 100644
--- a/sphinx/builders/html.py
+++ b/sphinx/builders/html.py
@@ -4,7 +4,7 @@
Several HTML builders.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -858,7 +858,7 @@ class StandaloneHTMLBuilder(Builder):
indexer_name, indexer_name),
RemovedInSphinx40Warning)
- def _get_local_toctree(self, docname: str, collapse: bool = True, **kwds) -> str:
+ def _get_local_toctree(self, docname: str, collapse: bool = True, **kwds: Any) -> str:
if 'includehidden' not in kwds:
kwds['includehidden'] = False
return self.render_partial(TocTree(self.env).get_toctree_for(
diff --git a/sphinx/builders/htmlhelp.py b/sphinx/builders/htmlhelp.py
index 7885acd08..8732de7fd 100644
--- a/sphinx/builders/htmlhelp.py
+++ b/sphinx/builders/htmlhelp.py
@@ -5,7 +5,7 @@
Build HTML help support files.
Parts adapted from Python's Doc/tools/prechm.py.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/builders/latex/__init__.py b/sphinx/builders/latex/__init__.py
index 8111044d5..23ef8e76b 100644
--- a/sphinx/builders/latex/__init__.py
+++ b/sphinx/builders/latex/__init__.py
@@ -4,7 +4,7 @@
LaTeX builder.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -216,7 +216,7 @@ class LaTeXBuilder(Builder):
'[2016/05/29 stylesheet for highlighting with pygments]\n\n')
f.write(highlighter.get_stylesheet())
- def write(self, *ignored) -> None:
+ def write(self, *ignored: Any) -> None:
docwriter = LaTeXWriter(self)
docsettings = OptionParser(
defaults=self.env.settings,
diff --git a/sphinx/builders/latex/nodes.py b/sphinx/builders/latex/nodes.py
index 2ffc2ef33..e6b1e5aee 100644
--- a/sphinx/builders/latex/nodes.py
+++ b/sphinx/builders/latex/nodes.py
@@ -4,7 +4,7 @@
Additional nodes for LaTeX writer.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/builders/latex/transforms.py b/sphinx/builders/latex/transforms.py
index 9fe44bc95..3ef0ff5d9 100644
--- a/sphinx/builders/latex/transforms.py
+++ b/sphinx/builders/latex/transforms.py
@@ -4,7 +4,7 @@
Transforms for LaTeX builder.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -32,7 +32,7 @@ class FootnoteDocnameUpdater(SphinxTransform):
default_priority = 700
TARGET_NODES = (nodes.footnote, nodes.footnote_reference)
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
matcher = NodeMatcher(*self.TARGET_NODES)
for node in self.document.traverse(matcher): # type: nodes.Element
node['docname'] = self.env.docname
@@ -51,7 +51,7 @@ class ShowUrlsTransform(SphinxPostTransform):
# references are expanded to footnotes (or not)
expanded = False
- def run(self, **kwargs) -> None:
+ def run(self, **kwargs: Any) -> None:
try:
# replace id_prefix temporarily
settings = self.document.settings # type: Any
@@ -338,7 +338,7 @@ class LaTeXFootnoteTransform(SphinxPostTransform):
default_priority = 600
builders = ('latex',)
- def run(self, **kwargs) -> None:
+ def run(self, **kwargs: Any) -> None:
footnotes = list(self.document.traverse(nodes.footnote))
for node in footnotes:
node.parent.remove(node)
@@ -490,7 +490,7 @@ class BibliographyTransform(SphinxPostTransform):
default_priority = 750
builders = ('latex',)
- def run(self, **kwargs) -> None:
+ def run(self, **kwargs: Any) -> None:
citations = thebibliography()
for node in self.document.traverse(nodes.citation):
node.parent.remove(node)
@@ -509,7 +509,7 @@ class CitationReferenceTransform(SphinxPostTransform):
default_priority = 5 # before ReferencesResolver
builders = ('latex',)
- def run(self, **kwargs) -> None:
+ def run(self, **kwargs: Any) -> 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
@@ -529,7 +529,7 @@ class MathReferenceTransform(SphinxPostTransform):
default_priority = 5 # before ReferencesResolver
builders = ('latex',)
- def run(self, **kwargs) -> None:
+ def run(self, **kwargs: Any) -> 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'):
@@ -544,7 +544,7 @@ class LiteralBlockTransform(SphinxPostTransform):
default_priority = 400
builders = ('latex',)
- def run(self, **kwargs) -> None:
+ def run(self, **kwargs: Any) -> 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)
@@ -556,7 +556,7 @@ class DocumentTargetTransform(SphinxPostTransform):
default_priority = 400
builders = ('latex',)
- def run(self, **kwargs) -> None:
+ def run(self, **kwargs: Any) -> None:
for node in self.document.traverse(addnodes.start_of_file):
section = node.next_node(nodes.section)
if section:
diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py
index ad80955fb..479b62a07 100644
--- a/sphinx/builders/linkcheck.py
+++ b/sphinx/builders/linkcheck.py
@@ -4,7 +4,7 @@
The CheckExternalLinksBuilder class.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/builders/manpage.py b/sphinx/builders/manpage.py
index 94b312e36..d4c7feb05 100644
--- a/sphinx/builders/manpage.py
+++ b/sphinx/builders/manpage.py
@@ -4,7 +4,7 @@
Manual pages builder.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -56,7 +56,7 @@ class ManualPageBuilder(Builder):
raise NoUri
@progress_message(__('writing'))
- def write(self, *ignored) -> None:
+ def write(self, *ignored: Any) -> None:
docwriter = ManualPageWriter(self)
docsettings = OptionParser(
defaults=self.env.settings,
diff --git a/sphinx/builders/qthelp.py b/sphinx/builders/qthelp.py
index 4053f437f..a4e73de9b 100644
--- a/sphinx/builders/qthelp.py
+++ b/sphinx/builders/qthelp.py
@@ -4,7 +4,7 @@
Build input files for the Qt collection generator.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/builders/singlehtml.py b/sphinx/builders/singlehtml.py
index 3309b024c..1c47596b8 100644
--- a/sphinx/builders/singlehtml.py
+++ b/sphinx/builders/singlehtml.py
@@ -4,7 +4,7 @@
Single HTML builders.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -67,7 +67,7 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder):
if hashindex >= 0:
refnode['refuri'] = fname + refuri[hashindex:]
- def _get_local_toctree(self, docname: str, collapse: bool = True, **kwds) -> str:
+ def _get_local_toctree(self, docname: str, collapse: bool = True, **kwds: Any) -> str:
if 'includehidden' not in kwds:
kwds['includehidden'] = False
toctree = TocTree(self.env).get_toctree_for(docname, self, collapse, **kwds)
@@ -149,7 +149,7 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder):
'display_toc': display_toc,
}
- def write(self, *ignored) -> None:
+ def write(self, *ignored: Any) -> None:
docnames = self.env.all_docs
with progress_message(__('preparing documents')):
diff --git a/sphinx/builders/texinfo.py b/sphinx/builders/texinfo.py
index 16f81c666..ed663be39 100644
--- a/sphinx/builders/texinfo.py
+++ b/sphinx/builders/texinfo.py
@@ -4,7 +4,7 @@
Texinfo builder.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -90,7 +90,7 @@ class TexinfoBuilder(Builder):
docname = docname[:-5]
self.titles.append((docname, entry[2]))
- def write(self, *ignored) -> None:
+ def write(self, *ignored: Any) -> None:
self.init_document_data()
for entry in self.document_data:
docname, targetname, title, author = entry[:4]
diff --git a/sphinx/builders/text.py b/sphinx/builders/text.py
index 475513cf9..89b041abd 100644
--- a/sphinx/builders/text.py
+++ b/sphinx/builders/text.py
@@ -4,7 +4,7 @@
Plain-text Sphinx builder.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/builders/xml.py b/sphinx/builders/xml.py
index a9f8bfc2c..81d729def 100644
--- a/sphinx/builders/xml.py
+++ b/sphinx/builders/xml.py
@@ -4,7 +4,7 @@
Docutils-native XML and pseudo-XML builders.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/cmd/__init__.py b/sphinx/cmd/__init__.py
index 0ad67d6fb..33fbf747b 100644
--- a/sphinx/cmd/__init__.py
+++ b/sphinx/cmd/__init__.py
@@ -4,6 +4,6 @@
Modules for command line executables.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/cmd/build.py b/sphinx/cmd/build.py
index 8f7b33a3b..bcf2a20c3 100644
--- a/sphinx/cmd/build.py
+++ b/sphinx/cmd/build.py
@@ -4,7 +4,7 @@
Build documentation from a provided source.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/cmd/make_mode.py b/sphinx/cmd/make_mode.py
index 682fe8d6c..aff2ea7f5 100644
--- a/sphinx/cmd/make_mode.py
+++ b/sphinx/cmd/make_mode.py
@@ -10,7 +10,7 @@
This is in its own module so that importing it is fast. It should not
import the main Sphinx modules (like sphinx.applications, sphinx.builders).
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py
index 83182ebf4..8f8ae58a1 100644
--- a/sphinx/cmd/quickstart.py
+++ b/sphinx/cmd/quickstart.py
@@ -4,7 +4,7 @@
Quickly setup documentation source to work with Sphinx.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/config.py b/sphinx/config.py
index ab00a0555..ca99fd5b7 100644
--- a/sphinx/config.py
+++ b/sphinx/config.py
@@ -4,7 +4,7 @@
Build configuration file handling.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/deprecation.py b/sphinx/deprecation.py
index 855e41599..5e5e673d2 100644
--- a/sphinx/deprecation.py
+++ b/sphinx/deprecation.py
@@ -4,7 +4,7 @@
Sphinx deprecation classes and utilities.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/directives/__init__.py b/sphinx/directives/__init__.py
index 393df0ca9..09390a6df 100644
--- a/sphinx/directives/__init__.py
+++ b/sphinx/directives/__init__.py
@@ -4,7 +4,7 @@
Handlers for additional ReST directives.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -253,12 +253,13 @@ from sphinx.directives.code import ( # noqa
Highlight, CodeBlock, LiteralInclude
)
from sphinx.directives.other import ( # noqa
- TocTree, Author, Index, VersionChange, SeeAlso,
+ TocTree, Author, VersionChange, SeeAlso,
TabularColumns, Centered, Acks, HList, Only, Include, Class
)
from sphinx.directives.patches import ( # noqa
Figure, Meta
)
+from sphinx.domains.index import IndexDirective # noqa
deprecated_alias('sphinx.directives',
{
@@ -267,7 +268,7 @@ deprecated_alias('sphinx.directives',
'LiteralInclude': LiteralInclude,
'TocTree': TocTree,
'Author': Author,
- 'Index': Index,
+ 'Index': IndexDirective,
'VersionChange': VersionChange,
'SeeAlso': SeeAlso,
'TabularColumns': TabularColumns,
diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py
index 3bcfb917f..8c19dd0c5 100644
--- a/sphinx/directives/code.py
+++ b/sphinx/directives/code.py
@@ -2,7 +2,7 @@
sphinx.directives.code
~~~~~~~~~~~~~~~~~~~~~~
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py
index a5a2831d6..bf7bd2784 100644
--- a/sphinx/directives/other.py
+++ b/sphinx/directives/other.py
@@ -2,7 +2,7 @@
sphinx.directives.other
~~~~~~~~~~~~~~~~~~~~~~~
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -18,12 +18,13 @@ from docutils.parsers.rst.directives.misc import Class
from docutils.parsers.rst.directives.misc import Include as BaseInclude
from sphinx import addnodes
+from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
from sphinx.domains.changeset import VersionChange # NOQA # for compatibility
from sphinx.locale import _
from sphinx.util import url_re, docname_join
from sphinx.util.docutils import SphinxDirective
from sphinx.util.matching import Matcher, patfilter
-from sphinx.util.nodes import explicit_title_re, process_index_entry
+from sphinx.util.nodes import explicit_title_re
if False:
# For type annotation
@@ -182,30 +183,6 @@ class Author(SphinxDirective):
return ret
-class Index(SphinxDirective):
- """
- Directive to add entries to the index.
- """
- has_content = False
- required_arguments = 1
- optional_arguments = 0
- final_argument_whitespace = True
- option_spec = {} # type: Dict
-
- def run(self) -> List[Node]:
- arguments = self.arguments[0].split('\n')
- targetid = 'index-%s' % self.env.new_serialno('index')
- targetnode = nodes.target('', '', ids=[targetid])
- self.state.document.note_explicit_target(targetnode)
- indexnode = addnodes.index()
- indexnode['entries'] = []
- indexnode['inline'] = False
- self.set_source_info(indexnode)
- for entry in arguments:
- indexnode['entries'].extend(process_index_entry(entry, targetid))
- return [indexnode, targetnode]
-
-
class SeeAlso(BaseAdmonition):
"""
An admonition mentioning things to look at as reference.
@@ -383,12 +360,21 @@ class Include(BaseInclude, SphinxDirective):
return super().run()
+# Import old modules here for compatibility
+from sphinx.domains.index import IndexDirective # NOQA
+
+deprecated_alias('sphinx.directives.other',
+ {
+ 'Index': IndexDirective,
+ },
+ RemovedInSphinx40Warning)
+
+
def setup(app: "Sphinx") -> Dict[str, Any]:
directives.register_directive('toctree', TocTree)
directives.register_directive('sectionauthor', Author)
directives.register_directive('moduleauthor', Author)
directives.register_directive('codeauthor', Author)
- directives.register_directive('index', Index)
directives.register_directive('seealso', SeeAlso)
directives.register_directive('tabularcolumns', TabularColumns)
directives.register_directive('centered', Centered)
diff --git a/sphinx/directives/patches.py b/sphinx/directives/patches.py
index 7bc13bf87..4b73a7955 100644
--- a/sphinx/directives/patches.py
+++ b/sphinx/directives/patches.py
@@ -2,7 +2,7 @@
sphinx.directives.patches
~~~~~~~~~~~~~~~~~~~~~~~~~
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/domains/__init__.py b/sphinx/domains/__init__.py
index a2109d3f7..b521cd025 100644
--- a/sphinx/domains/__init__.py
+++ b/sphinx/domains/__init__.py
@@ -5,7 +5,7 @@
Support for domains, which are groupings of description directives
and roles describing e.g. constructs of one programming language.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -48,7 +48,7 @@ class ObjType:
'searchprio': 1,
}
- def __init__(self, lname: str, *roles, **attrs) -> None:
+ def __init__(self, lname: str, *roles: Any, **attrs: Any) -> None:
self.lname = lname
self.roles = roles # type: Tuple
self.attrs = self.known_attrs.copy() # type: Dict
diff --git a/sphinx/domains/c.py b/sphinx/domains/c.py
index e319771be..cc24df47e 100644
--- a/sphinx/domains/c.py
+++ b/sphinx/domains/c.py
@@ -4,7 +4,7 @@
The C language domain.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/domains/changeset.py b/sphinx/domains/changeset.py
index 067587a96..a07944db8 100644
--- a/sphinx/domains/changeset.py
+++ b/sphinx/domains/changeset.py
@@ -4,7 +4,7 @@
The changeset domain.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/domains/citation.py b/sphinx/domains/citation.py
index 0b512c365..38901867a 100644
--- a/sphinx/domains/citation.py
+++ b/sphinx/domains/citation.py
@@ -4,7 +4,7 @@
The citation domain.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -112,7 +112,7 @@ class CitationDefinitionTransform(SphinxTransform):
"""Mark citation definition labels as not smartquoted."""
default_priority = 619
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
domain = cast(CitationDomain, self.env.get_domain('citation'))
for node in self.document.traverse(nodes.citation):
# register citation node to domain
@@ -131,7 +131,7 @@ class CitationReferenceTransform(SphinxTransform):
"""
default_priority = 619
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
domain = cast(CitationDomain, self.env.get_domain('citation'))
for node in self.document.traverse(nodes.citation_reference):
target = node.astext()
diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py
index 4928fb997..eda04b9f4 100644
--- a/sphinx/domains/cpp.py
+++ b/sphinx/domains/cpp.py
@@ -4,21 +4,28 @@
The C++ language domain.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
import warnings
from copy import deepcopy
+from typing import Any, Callable, Dict, Iterator, List, Match, Pattern, Tuple, Type, Union
from docutils import nodes, utils
+from docutils.nodes import Element, Node, TextElement
from docutils.parsers.rst import directives
from sphinx import addnodes
+from sphinx.addnodes import desc_signature, pending_xref
+from sphinx.application import Sphinx
+from sphinx.builders import Builder
+from sphinx.config import Config
from sphinx.deprecation import RemovedInSphinx40Warning
from sphinx.directives import ObjectDescription
from sphinx.domains import Domain, ObjType
+from sphinx.environment import BuildEnvironment
from sphinx.errors import NoUri
from sphinx.locale import _, __
from sphinx.roles import XRefRole
@@ -30,16 +37,8 @@ from sphinx.util.docutils import SphinxDirective
from sphinx.util.nodes import make_refnode
-if False:
- # For type annotation
- from docutils.nodes import TextElement
- from typing import Any, Callable, Dict, Iterator, List, Match, Pattern, Tuple, Type, Union # NOQA
- from sphinx.application import Sphinx # NOQA
- from sphinx.builders import Builder # NOQA
- from sphinx.config import Config # NOQA
- from sphinx.environment import BuildEnvironment # NOQA
-
logger = logging.getLogger(__name__)
+StringifyTransform = Callable[[Any], str]
"""
Important note on ids
@@ -580,8 +579,7 @@ _id_explicit_cast = {
class NoOldIdError(Exception):
# Used to avoid implementing unneeded id generation for old id schemes.
@property
- def description(self):
- # type: () -> str
+ def description(self) -> str:
warnings.warn('%s.description is deprecated. '
'Coerce the instance to a string instead.' % self.__class__.__name__,
RemovedInSphinx40Warning, stacklevel=2)
@@ -590,8 +588,7 @@ class NoOldIdError(Exception):
class DefinitionError(Exception):
@property
- def description(self):
- # type: () -> str
+ def description(self) -> str:
warnings.warn('%s.description is deprecated. '
'Coerce the instance to a string instead.' % self.__class__.__name__,
RemovedInSphinx40Warning, stacklevel=2)
@@ -599,21 +596,18 @@ class DefinitionError(Exception):
class _DuplicateSymbolError(Exception):
- def __init__(self, symbol, declaration):
- # type: (Symbol, Any) -> None
+ def __init__(self, symbol: "Symbol", declaration: Any) -> None:
assert symbol
assert declaration
self.symbol = symbol
self.declaration = declaration
- def __str__(self):
- # type: () -> str
+ def __str__(self) -> str:
return "Internal C++ duplicate symbol error:\n%s" % self.symbol.dump(0)
class ASTBase:
- def __eq__(self, other):
- # type: (Any) -> bool
+ def __eq__(self, other: Any) -> bool:
if type(self) is not type(other):
return False
try:
@@ -626,30 +620,24 @@ class ASTBase:
__hash__ = None # type: Callable[[], int]
- def clone(self):
- # type: () -> Any
+ def clone(self) -> Any:
"""Clone a definition expression node."""
return deepcopy(self)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
raise NotImplementedError(repr(self))
- def __str__(self):
- # type: () -> str
+ def __str__(self) -> str:
return self._stringify(lambda ast: str(ast))
- def get_display_string(self):
- # type: () -> str
+ def get_display_string(self) -> str:
return self._stringify(lambda ast: ast.get_display_string())
- def __repr__(self):
- # type: () -> str
+ def __repr__(self) -> str:
return '<%s>' % self.__class__.__name__
-def _verify_description_mode(mode):
- # type: (str) -> None
+def _verify_description_mode(mode: str) -> None:
if mode not in ('lastIsName', 'noneIsName', 'markType', 'markName', 'param'):
raise Exception("Description mode '%s' is invalid." % mode)
@@ -659,27 +647,23 @@ def _verify_description_mode(mode):
################################################################################
class ASTCPPAttribute(ASTBase):
- def __init__(self, arg):
- # type: (str) -> None
+ def __init__(self, arg: str) -> None:
self.arg = arg
def _stringify(self, transform):
return "[[" + self.arg + "]]"
- def describe_signature(self, signode):
- # type: (addnodes.desc_signature) -> None
+ def describe_signature(self, signode: desc_signature) -> None:
txt = str(self)
signode.append(nodes.Text(txt, txt))
class ASTGnuAttribute(ASTBase):
- def __init__(self, name, args):
- # type: (str, Any) -> None
+ def __init__(self, name: str, args: Any) -> None:
self.name = name
self.args = args
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = [self.name]
if self.args:
res.append('(')
@@ -689,12 +673,10 @@ class ASTGnuAttribute(ASTBase):
class ASTGnuAttributeList(ASTBase):
- def __init__(self, attrs):
- # type: (List[Any]) -> None
+ def __init__(self, attrs: List[Any]) -> None:
self.attrs = attrs
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = ['__attribute__((']
first = True
for attr in self.attrs:
@@ -705,8 +687,7 @@ class ASTGnuAttributeList(ASTBase):
res.append('))')
return ''.join(res)
- def describe_signature(self, signode):
- # type: (addnodes.desc_signature) -> None
+ def describe_signature(self, signode: desc_signature) -> None:
txt = str(self)
signode.append(nodes.Text(txt, txt))
@@ -714,33 +695,27 @@ class ASTGnuAttributeList(ASTBase):
class ASTIdAttribute(ASTBase):
"""For simple attributes defined by the user."""
- def __init__(self, id):
- # type: (str) -> None
+ def __init__(self, id: str) -> None:
self.id = id
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return self.id
- def describe_signature(self, signode):
- # type: (addnodes.desc_signature) -> None
+ def describe_signature(self, signode: desc_signature) -> None:
signode.append(nodes.Text(self.id, self.id))
class ASTParenAttribute(ASTBase):
"""For paren attributes defined by the user."""
- def __init__(self, id, arg):
- # type: (str, str) -> None
+ def __init__(self, id: str, arg: str) -> None:
self.id = id
self.arg = arg
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return self.id + '(' + self.arg + ')'
- def describe_signature(self, signode):
- # type: (addnodes.desc_signature) -> None
+ def describe_signature(self, signode: desc_signature) -> None:
txt = str(self)
signode.append(nodes.Text(txt, txt))
@@ -750,12 +725,10 @@ class ASTParenAttribute(ASTBase):
################################################################################
class ASTPointerLiteral(ASTBase):
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return 'nullptr'
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
return 'LDnE'
def describe_signature(self, signode, mode, env, symbol):
@@ -766,15 +739,13 @@ class ASTBooleanLiteral(ASTBase):
def __init__(self, value):
self.value = value
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
if self.value:
return 'true'
else:
return 'false'
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
if self.value:
return 'L1E'
else:
@@ -785,16 +756,13 @@ class ASTBooleanLiteral(ASTBase):
class ASTNumberLiteral(ASTBase):
- def __init__(self, data):
- # type: (str) -> None
+ def __init__(self, data: str) -> None:
self.data = data
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return self.data
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
return "L%sE" % self.data
def describe_signature(self, signode, mode, env, symbol):
@@ -804,8 +772,7 @@ class ASTNumberLiteral(ASTBase):
class UnsupportedMultiCharacterCharLiteral(Exception):
@property
- def decoded(self):
- # type: () -> str
+ def decoded(self) -> str:
warnings.warn('%s.decoded is deprecated. '
'Coerce the instance to a string instead.' % self.__class__.__name__,
RemovedInSphinx40Warning, stacklevel=2)
@@ -813,8 +780,7 @@ class UnsupportedMultiCharacterCharLiteral(Exception):
class ASTCharLiteral(ASTBase):
- def __init__(self, prefix, data):
- # type: (str, str) -> None
+ def __init__(self, prefix: str, data: str) -> None:
self.prefix = prefix # may be None when no prefix
self.data = data
assert prefix in _id_char_from_prefix
@@ -825,15 +791,13 @@ class ASTCharLiteral(ASTBase):
else:
raise UnsupportedMultiCharacterCharLiteral(decoded)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
if self.prefix is None:
return "'" + self.data + "'"
else:
return self.prefix + "'" + self.data + "'"
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
return self.type + str(self.value)
def describe_signature(self, signode, mode, env, symbol):
@@ -842,16 +806,13 @@ class ASTCharLiteral(ASTBase):
class ASTStringLiteral(ASTBase):
- def __init__(self, data):
- # type: (str) -> None
+ def __init__(self, data: str) -> None:
self.data = data
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return self.data
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
# note: the length is not really correct with escaping
return "LA%d_KcE" % (len(self.data) - 2)
@@ -861,12 +822,10 @@ class ASTStringLiteral(ASTBase):
class ASTThisLiteral(ASTBase):
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return "this"
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
return "fpT"
def describe_signature(self, signode, mode, env, symbol):
@@ -877,12 +836,10 @@ class ASTParenExpr(ASTBase):
def __init__(self, expr):
self.expr = expr
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return '(' + transform(self.expr) + ')'
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
return self.expr.get_id(version)
def describe_signature(self, signode, mode, env, symbol):
@@ -892,15 +849,13 @@ class ASTParenExpr(ASTBase):
class ASTFoldExpr(ASTBase):
- def __init__(self, leftExpr, op, rightExpr):
- # type: (Any, str, Any) -> None
+ def __init__(self, leftExpr: Any, op: str, rightExpr: Any) -> None:
assert leftExpr is not None or rightExpr is not None
self.leftExpr = leftExpr
self.op = op
self.rightExpr = rightExpr
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = ['(']
if self.leftExpr:
res.append(transform(self.leftExpr))
@@ -916,8 +871,7 @@ class ASTFoldExpr(ASTBase):
res.append(')')
return ''.join(res)
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
assert version >= 3
if version == 3:
return str(self)
@@ -961,8 +915,7 @@ class ASTBinOpExpr(ASTBase):
self.exprs = exprs
self.ops = ops
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
res.append(transform(self.exprs[0]))
for i in range(1, len(self.exprs)):
@@ -972,8 +925,7 @@ class ASTBinOpExpr(ASTBase):
res.append(transform(self.exprs[i]))
return ''.join(res)
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
assert version >= 2
res = []
for i in range(len(self.ops)):
@@ -998,8 +950,7 @@ class ASTAssignmentExpr(ASTBase):
self.exprs = exprs
self.ops = ops
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
res.append(transform(self.exprs[0]))
for i in range(1, len(self.exprs)):
@@ -1009,8 +960,7 @@ class ASTAssignmentExpr(ASTBase):
res.append(transform(self.exprs[i]))
return ''.join(res)
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
res = []
for i in range(len(self.ops)):
res.append(_id_operator_v2[self.ops[i]])
@@ -1032,16 +982,14 @@ class ASTCastExpr(ASTBase):
self.typ = typ
self.expr = expr
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = ['(']
res.append(transform(self.typ))
res.append(')')
res.append(transform(self.expr))
return ''.join(res)
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
return 'cv' + self.typ.get_id(version) + self.expr.get_id(version)
def describe_signature(self, signode, mode, env, symbol):
@@ -1056,12 +1004,10 @@ class ASTUnaryOpExpr(ASTBase):
self.op = op
self.expr = expr
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return transform(self.op) + transform(self.expr)
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
return _id_operator_unary_v2[self.op] + self.expr.get_id(version)
def describe_signature(self, signode, mode, env, symbol):
@@ -1073,12 +1019,10 @@ class ASTSizeofParamPack(ASTBase):
def __init__(self, identifier):
self.identifier = identifier
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return "sizeof...(" + transform(self.identifier) + ")"
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
return 'sZ' + self.identifier.get_id(version)
def describe_signature(self, signode, mode, env, symbol):
@@ -1092,12 +1036,10 @@ class ASTSizeofType(ASTBase):
def __init__(self, typ):
self.typ = typ
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return "sizeof(" + transform(self.typ) + ")"
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
return 'st' + self.typ.get_id(version)
def describe_signature(self, signode, mode, env, symbol):
@@ -1110,12 +1052,10 @@ class ASTSizeofExpr(ASTBase):
def __init__(self, expr):
self.expr = expr
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return "sizeof " + transform(self.expr)
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
return 'sz' + self.expr.get_id(version)
def describe_signature(self, signode, mode, env, symbol):
@@ -1127,12 +1067,10 @@ class ASTAlignofExpr(ASTBase):
def __init__(self, typ):
self.typ = typ
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return "alignof(" + transform(self.typ) + ")"
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
return 'at' + self.typ.get_id(version)
def describe_signature(self, signode, mode, env, symbol):
@@ -1145,12 +1083,10 @@ class ASTNoexceptExpr(ASTBase):
def __init__(self, expr):
self.expr = expr
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return "noexcept(" + transform(self.expr) + ")"
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
return 'nx' + self.expr.get_id(version)
def describe_signature(self, signode, mode, env, symbol):
@@ -1160,15 +1096,13 @@ class ASTNoexceptExpr(ASTBase):
class ASTNewExpr(ASTBase):
- def __init__(self, rooted, isNewTypeId, typ, initList):
- # type: (bool, bool, ASTType, Any) -> None
+ def __init__(self, rooted: bool, isNewTypeId: bool, typ: "ASTType", initList: Any) -> None:
self.rooted = rooted
self.isNewTypeId = isNewTypeId
self.typ = typ
self.initList = initList
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
if self.rooted:
res.append('::')
@@ -1182,8 +1116,7 @@ class ASTNewExpr(ASTBase):
res.append(transform(self.initList))
return ''.join(res)
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
# the array part will be in the type mangling, so na is not used
res = ['nw']
# TODO: placement
@@ -1214,8 +1147,7 @@ class ASTDeleteExpr(ASTBase):
self.array = array
self.expr = expr
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
if self.rooted:
res.append('::')
@@ -1225,8 +1157,7 @@ class ASTDeleteExpr(ASTBase):
res.append(transform(self.expr))
return ''.join(res)
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
if self.array:
id = "da"
else:
@@ -1249,8 +1180,7 @@ class ASTExplicitCast(ASTBase):
self.typ = typ
self.expr = expr
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = [self.cast]
res.append('<')
res.append(transform(self.typ))
@@ -1259,8 +1189,7 @@ class ASTExplicitCast(ASTBase):
res.append(')')
return ''.join(res)
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
return (_id_explicit_cast[self.cast] +
self.typ.get_id(version) +
self.expr.get_id(version))
@@ -1280,12 +1209,10 @@ class ASTTypeId(ASTBase):
self.typeOrExpr = typeOrExpr
self.isType = isType
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return 'typeid(' + transform(self.typeOrExpr) + ')'
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
prefix = 'ti' if self.isType else 'te'
return prefix + self.typeOrExpr.get_id(version)
@@ -1297,16 +1224,13 @@ class ASTTypeId(ASTBase):
class ASTPostfixCallExpr(ASTBase):
- def __init__(self, lst):
- # type: (Union[ASTParenExprList, ASTBracedInitList]) -> None
+ def __init__(self, lst: Union["ASTParenExprList", "ASTBracedInitList"]) -> None:
self.lst = lst
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return transform(self.lst)
- def get_id(self, idPrefix, version):
- # type: (str, int) -> str
+ def get_id(self, idPrefix: str, version: int) -> str:
res = ['cl', idPrefix]
for e in self.lst.exprs:
res.append(e.get_id(version))
@@ -1321,12 +1245,10 @@ class ASTPostfixArray(ASTBase):
def __init__(self, expr):
self.expr = expr
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return '[' + transform(self.expr) + ']'
- def get_id(self, idPrefix, version):
- # type: (str, int) -> str
+ def get_id(self, idPrefix: str, version: int) -> str:
return 'ix' + idPrefix + self.expr.get_id(version)
def describe_signature(self, signode, mode, env, symbol):
@@ -1336,12 +1258,10 @@ class ASTPostfixArray(ASTBase):
class ASTPostfixInc(ASTBase):
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return '++'
- def get_id(self, idPrefix, version):
- # type: (str, int) -> str
+ def get_id(self, idPrefix: str, version: int) -> str:
return 'pp' + idPrefix
def describe_signature(self, signode, mode, env, symbol):
@@ -1349,12 +1269,10 @@ class ASTPostfixInc(ASTBase):
class ASTPostfixDec(ASTBase):
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return '--'
- def get_id(self, idPrefix, version):
- # type: (str, int) -> str
+ def get_id(self, idPrefix: str, version: int) -> str:
return 'mm' + idPrefix
def describe_signature(self, signode, mode, env, symbol):
@@ -1365,12 +1283,10 @@ class ASTPostfixMember(ASTBase):
def __init__(self, name):
self.name = name
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return '.' + transform(self.name)
- def get_id(self, idPrefix, version):
- # type: (str, int) -> str
+ def get_id(self, idPrefix: str, version: int) -> str:
return 'dt' + idPrefix + self.name.get_id(version)
def describe_signature(self, signode, mode, env, symbol):
@@ -1382,12 +1298,10 @@ class ASTPostfixMemberOfPointer(ASTBase):
def __init__(self, name):
self.name = name
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return '->' + transform(self.name)
- def get_id(self, idPrefix, version):
- # type: (str, int) -> str
+ def get_id(self, idPrefix: str, version: int) -> str:
return 'pt' + idPrefix + self.name.get_id(version)
def describe_signature(self, signode, mode, env, symbol):
@@ -1401,15 +1315,13 @@ class ASTPostfixExpr(ASTBase):
self.prefix = prefix
self.postFixes = postFixes
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = [transform(self.prefix)]
for p in self.postFixes:
res.append(transform(p))
return ''.join(res)
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
id = self.prefix.get_id(version)
for p in self.postFixes:
id = p.get_id(id, version)
@@ -1425,12 +1337,10 @@ class ASTPackExpansionExpr(ASTBase):
def __init__(self, expr):
self.expr = expr
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return transform(self.expr) + '...'
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
id = self.expr.get_id(version)
return 'sp' + id
@@ -1443,12 +1353,10 @@ class ASTFallbackExpr(ASTBase):
def __init__(self, expr):
self.expr = expr
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return self.expr
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
return str(self.expr)
def describe_signature(self, signode, mode, env, symbol):
@@ -1460,17 +1368,15 @@ class ASTFallbackExpr(ASTBase):
################################################################################
class ASTIdentifier(ASTBase):
- def __init__(self, identifier):
- # type: (str) -> None
+ def __init__(self, identifier: str) -> None:
assert identifier is not None
assert len(identifier) != 0
self.identifier = identifier
- def is_anon(self):
+ def is_anon(self) -> bool:
return self.identifier[0] == '@'
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
if self.is_anon() and version < 3:
raise NoOldIdError()
if version == 1:
@@ -1491,16 +1397,14 @@ class ASTIdentifier(ASTBase):
# and this is where we finally make a difference between __str__ and the display string
- def __str__(self):
- # type: () -> str
+ def __str__(self) -> str:
return self.identifier
- def get_display_string(self):
- # type: () -> str
+ def get_display_string(self) -> str:
return "[anonymous]" if self.is_anon() else self.identifier
- def describe_signature(self, signode, mode, env, prefix, templateArgs, symbol):
- # type: (Any, str, BuildEnvironment, str, str, Symbol) -> None
+ def describe_signature(self, signode: Any, mode: str, env: "BuildEnvironment",
+ prefix: str, templateArgs: str, symbol: "Symbol") -> None:
_verify_description_mode(mode)
if mode == 'markType':
targetText = prefix + self.identifier + templateArgs
@@ -1530,8 +1434,8 @@ class ASTIdentifier(ASTBase):
class ASTTemplateKeyParamPackIdDefault(ASTBase):
- def __init__(self, key, identifier, parameterPack, default):
- # type: (str, ASTIdentifier, bool, ASTType) -> None
+ def __init__(self, key: str, identifier: ASTIdentifier,
+ parameterPack: bool, default: "ASTType") -> None:
assert key
if parameterPack:
assert default is None
@@ -1540,12 +1444,10 @@ class ASTTemplateKeyParamPackIdDefault(ASTBase):
self.parameterPack = parameterPack
self.default = default
- def get_identifier(self):
- # type: () -> ASTIdentifier
+ def get_identifier(self) -> ASTIdentifier:
return self.identifier
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
assert version >= 2
# this is not part of the normal name mangling in C++
res = []
@@ -1555,8 +1457,7 @@ class ASTTemplateKeyParamPackIdDefault(ASTBase):
res.append('0') # we need to put something
return ''.join(res)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = [self.key]
if self.parameterPack:
if self.identifier:
@@ -1571,8 +1472,8 @@ class ASTTemplateKeyParamPackIdDefault(ASTBase):
res.append(transform(self.default))
return ''.join(res)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
signode += nodes.Text(self.key)
if self.parameterPack:
if self.identifier:
@@ -1588,28 +1489,23 @@ class ASTTemplateKeyParamPackIdDefault(ASTBase):
class ASTTemplateParamType(ASTBase):
- def __init__(self, data):
- # type: (ASTTemplateKeyParamPackIdDefault) -> None
+ def __init__(self, data: ASTTemplateKeyParamPackIdDefault) -> None:
assert data
self.data = data
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> "ASTNestedName":
id = self.get_identifier()
return ASTNestedName([ASTNestedNameElement(id, None)], [False], rooted=False)
@property
- def isPack(self):
- # type: () -> bool
+ def isPack(self) -> bool:
return self.data.parameterPack
- def get_identifier(self):
- # type: () -> ASTIdentifier
+ def get_identifier(self) -> ASTIdentifier:
return self.data.get_identifier()
- def get_id(self, version, objectType=None, symbol=None):
- # type: (int, str, Symbol) -> str
+ def get_id(self, version: int, objectType: str = None, symbol: "Symbol" = None) -> str:
# this is not part of the normal name mangling in C++
assert version >= 2
if symbol:
@@ -1618,34 +1514,29 @@ class ASTTemplateParamType(ASTBase):
else:
return self.data.get_id(version)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return transform(self.data)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
self.data.describe_signature(signode, mode, env, symbol)
class ASTTemplateParamConstrainedTypeWithInit(ASTBase):
- def __init__(self, type, init):
- # type: (Any, Any) -> None
+ def __init__(self, type: Any, init: Any) -> None:
assert type
self.type = type
self.init = init
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> "ASTNestedName":
return self.type.name
@property
- def isPack(self):
- # type: () -> bool
+ def isPack(self) -> bool:
return self.type.isPack
- def get_id(self, version, objectType=None, symbol=None):
- # type: (int, str, Symbol) -> str
+ def get_id(self, version: int, objectType: str = None, symbol: "Symbol" = None) -> str:
# this is not part of the normal name mangling in C++
assert version >= 2
if symbol:
@@ -1654,16 +1545,15 @@ class ASTTemplateParamConstrainedTypeWithInit(ASTBase):
else:
return self.type.get_id(version)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = transform(self.type)
if self.init:
res += " = "
res += transform(self.init)
return res
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
self.type.describe_signature(signode, mode, env, symbol)
if self.init:
signode += nodes.Text(" = ")
@@ -1671,30 +1561,25 @@ class ASTTemplateParamConstrainedTypeWithInit(ASTBase):
class ASTTemplateParamTemplateType(ASTBase):
- def __init__(self, nestedParams, data):
- # type: (Any, ASTTemplateKeyParamPackIdDefault) -> None
+ def __init__(self, nestedParams: Any, data: ASTTemplateKeyParamPackIdDefault) -> None:
assert nestedParams
assert data
self.nestedParams = nestedParams
self.data = data
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> "ASTNestedName":
id = self.get_identifier()
return ASTNestedName([ASTNestedNameElement(id, None)], [False], rooted=False)
@property
- def isPack(self):
- # type: () -> bool
+ def isPack(self) -> bool:
return self.data.parameterPack
- def get_identifier(self):
- # type: () -> ASTIdentifier
+ def get_identifier(self) -> ASTIdentifier:
return self.data.get_identifier()
- def get_id(self, version, objectType=None, symbol=None):
- # type: (int, str, Symbol) -> str
+ def get_id(self, version: int, objectType: str = None, symbol: "Symbol" = None) -> str:
assert version >= 2
# this is not part of the normal name mangling in C++
if symbol:
@@ -1703,36 +1588,31 @@ class ASTTemplateParamTemplateType(ASTBase):
else:
return self.nestedParams.get_id(version) + self.data.get_id(version)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return transform(self.nestedParams) + transform(self.data)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
self.nestedParams.describe_signature(signode, 'noneIsName', env, symbol)
signode += nodes.Text(' ')
self.data.describe_signature(signode, mode, env, symbol)
class ASTTemplateParamNonType(ASTBase):
- def __init__(self, param):
- # type: (Any) -> None
+ def __init__(self, param: Any) -> None:
assert param
self.param = param
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> "ASTNestedName":
id = self.get_identifier()
return ASTNestedName([ASTNestedNameElement(id, None)], [False], rooted=False)
@property
- def isPack(self):
- # type: () -> bool
+ def isPack(self) -> bool:
return self.param.isPack
- def get_identifier(self):
- # type: () -> ASTIdentifier
+ def get_identifier(self) -> ASTIdentifier:
name = self.param.name
if name:
assert len(name.names) == 1
@@ -1742,8 +1622,7 @@ class ASTTemplateParamNonType(ASTBase):
else:
return None
- def get_id(self, version, objectType=None, symbol=None):
- # type: (int, str, Symbol) -> str
+ def get_id(self, version: int, objectType: str = None, symbol: "Symbol" = None) -> str:
assert version >= 2
# this is not part of the normal name mangling in C++
if symbol:
@@ -1752,24 +1631,21 @@ class ASTTemplateParamNonType(ASTBase):
else:
return '_' + self.param.get_id(version)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return transform(self.param)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
self.param.describe_signature(signode, mode, env, symbol)
class ASTTemplateParams(ASTBase):
- def __init__(self, params):
- # type: (Any) -> None
+ def __init__(self, params: Any) -> None:
assert params is not None
self.params = params
self.isNested = False # whether it's a template template param
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
assert version >= 2
res = []
res.append("I")
@@ -1778,16 +1654,16 @@ class ASTTemplateParams(ASTBase):
res.append("E")
return ''.join(res)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
res.append("template<")
res.append(", ".join(transform(a) for a in self.params))
res.append("> ")
return ''.join(res)
- def describe_signature(self, parentNode, mode, env, symbol, lineSpec=None):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol, bool) -> None
+ def describe_signature(self, parentNode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol", lineSpec: bool = None
+ ) -> None:
# 'lineSpec' is defaulted becuase of template template parameters
def makeLine(parentNode=parentNode):
signode = addnodes.desc_signature_line()
@@ -1813,28 +1689,23 @@ class ASTTemplateParams(ASTBase):
class ASTTemplateIntroductionParameter(ASTBase):
- def __init__(self, identifier, parameterPack):
- # type: (ASTIdentifier, bool) -> None
+ def __init__(self, identifier: ASTIdentifier, parameterPack: bool) -> None:
self.identifier = identifier
self.parameterPack = parameterPack
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> "ASTNestedName":
id = self.get_identifier()
return ASTNestedName([ASTNestedNameElement(id, None)], [False], rooted=False)
@property
- def isPack(self):
- # type: () -> bool
+ def isPack(self) -> bool:
return self.parameterPack
- def get_identifier(self):
- # type: () -> ASTIdentifier
+ def get_identifier(self) -> ASTIdentifier:
return self.identifier
- def get_id(self, version, objectType=None, symbol=None):
- # type: (int, str, Symbol) -> str
+ def get_id(self, version: int, objectType: str = None, symbol: "Symbol" = None) -> str:
assert version >= 2
# this is not part of the normal name mangling in C++
if symbol:
@@ -1846,8 +1717,7 @@ class ASTTemplateIntroductionParameter(ASTBase):
else:
return '0' # we need to put something
- def get_id_as_arg(self, version):
- # type: (int) -> str
+ def get_id_as_arg(self, version: int) -> str:
assert version >= 2
# used for the implicit requires clause
res = self.identifier.get_id(version)
@@ -1856,30 +1726,27 @@ class ASTTemplateIntroductionParameter(ASTBase):
else:
return res
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
if self.parameterPack:
res.append('...')
res.append(transform(self.identifier))
return ''.join(res)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
if self.parameterPack:
signode += nodes.Text('...')
self.identifier.describe_signature(signode, mode, env, '', '', symbol)
class ASTTemplateIntroduction(ASTBase):
- def __init__(self, concept, params):
- # type: (Any, List[Any]) -> None
+ def __init__(self, concept: Any, params: List[Any]) -> None:
assert len(params) > 0
self.concept = concept
self.params = params
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
assert version >= 2
# first do the same as a normal template parameter list
res = []
@@ -1897,8 +1764,7 @@ class ASTTemplateIntroduction(ASTBase):
res.append("E")
return ''.join(res)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
res.append(transform(self.concept))
res.append('{')
@@ -1906,8 +1772,8 @@ class ASTTemplateIntroduction(ASTBase):
res.append('} ')
return ''.join(res)
- def describe_signature(self, parentNode, mode, env, symbol, lineSpec):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol, bool) -> None
+ def describe_signature(self, parentNode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol", lineSpec: bool) -> None:
# Note: 'lineSpec' has no effect on template introductions.
signode = addnodes.desc_signature_line()
parentNode += signode
@@ -1924,13 +1790,11 @@ class ASTTemplateIntroduction(ASTBase):
class ASTTemplateDeclarationPrefix(ASTBase):
- def __init__(self, templates):
- # type: (List[Any]) -> None
+ def __init__(self, templates: List[Any]) -> None:
# templates is None means it's an explicit instantiation of a variable
self.templates = templates
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
assert version >= 2
# this is not part of a normal name mangling system
res = []
@@ -1938,15 +1802,14 @@ class ASTTemplateDeclarationPrefix(ASTBase):
res.append(t.get_id(version))
return ''.join(res)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
for t in self.templates:
res.append(transform(t))
return ''.join(res)
- def describe_signature(self, signode, mode, env, symbol, lineSpec):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol, bool) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol", lineSpec: bool) -> None:
_verify_description_mode(mode)
for t in self.templates:
t.describe_signature(signode, 'lastIsName', env, symbol, lineSpec)
@@ -1959,16 +1822,15 @@ class ASTOperator(ASTBase):
def is_anon(self):
return False
- def is_operator(self):
- # type: () -> bool
+ def is_operator(self) -> bool:
return True
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
raise NotImplementedError()
- def describe_signature(self, signode, mode, env, prefix, templateArgs, symbol):
- # type: (addnodes.desc_signature, str, Any, str, str, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", prefix: str, templateArgs: str,
+ symbol: "Symbol") -> None:
_verify_description_mode(mode)
identifier = str(self)
if mode == 'lastIsName':
@@ -1978,12 +1840,10 @@ class ASTOperator(ASTBase):
class ASTOperatorBuildIn(ASTOperator):
- def __init__(self, op):
- # type: (str) -> None
+ def __init__(self, op: str) -> None:
self.op = op
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
if version == 1:
ids = _id_operator_v1
else:
@@ -1993,8 +1853,7 @@ class ASTOperatorBuildIn(ASTOperator):
'be mapped to an id.' % self.op)
return ids[self.op]
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
if self.op in ('new', 'new[]', 'delete', 'delete[]'):
return 'operator ' + self.op
else:
@@ -2002,40 +1861,33 @@ class ASTOperatorBuildIn(ASTOperator):
class ASTOperatorType(ASTOperator):
- def __init__(self, type):
- # type: (Any) -> None
+ def __init__(self, type: Any) -> None:
self.type = type
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
if version == 1:
return 'castto-%s-operator' % self.type.get_id(version)
else:
return 'cv' + self.type.get_id(version)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return ''.join(['operator ', transform(self.type)])
- def get_name_no_template(self):
- # type: () -> str
+ def get_name_no_template(self) -> str:
return str(self)
class ASTOperatorLiteral(ASTOperator):
- def __init__(self, identifier):
- # type: (Any) -> None
+ def __init__(self, identifier: Any) -> None:
self.identifier = identifier
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
if version == 1:
raise NoOldIdError()
else:
return 'li' + self.identifier.get_id(version)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return 'operator""' + transform(self.identifier)
@@ -2043,36 +1895,31 @@ class ASTOperatorLiteral(ASTOperator):
class ASTTemplateArgConstant(ASTBase):
- def __init__(self, value):
- # type: (Any) -> None
+ def __init__(self, value: Any) -> None:
self.value = value
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return transform(self.value)
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
if version == 1:
return str(self).replace(' ', '-')
if version == 2:
return 'X' + str(self) + 'E'
return 'X' + self.value.get_id(version) + 'E'
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
self.value.describe_signature(signode, mode, env, symbol)
class ASTTemplateArgs(ASTBase):
- def __init__(self, args):
- # type: (List[Any]) -> None
+ def __init__(self, args: List[Any]) -> None:
assert args is not None
self.args = args
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
if version == 1:
res = []
res.append(':')
@@ -2087,13 +1934,12 @@ class ASTTemplateArgs(ASTBase):
res.append('E')
return ''.join(res)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = ', '.join(transform(a) for a in self.args)
return '<' + res + '>'
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
signode += nodes.Text('<')
first = True
@@ -2106,31 +1952,28 @@ class ASTTemplateArgs(ASTBase):
class ASTNestedNameElement(ASTBase):
- def __init__(self, identOrOp, templateArgs):
- # type: (Union[ASTIdentifier, ASTOperator], ASTTemplateArgs) -> None
+ def __init__(self, identOrOp: Union["ASTIdentifier", "ASTOperator"],
+ templateArgs: ASTTemplateArgs) -> None:
self.identOrOp = identOrOp
self.templateArgs = templateArgs
- def is_operator(self):
- # type: () -> bool
+ def is_operator(self) -> bool:
return False
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
res = self.identOrOp.get_id(version)
if self.templateArgs:
res += self.templateArgs.get_id(version)
return res
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = transform(self.identOrOp)
if self.templateArgs:
res += transform(self.templateArgs)
return res
- def describe_signature(self, signode, mode, env, prefix, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, str, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", prefix: str, symbol: "Symbol") -> None:
tArgs = str(self.templateArgs) if self.templateArgs is not None else ''
self.identOrOp.describe_signature(signode, mode, env, prefix, tArgs, symbol)
if self.templateArgs is not None:
@@ -2138,8 +1981,8 @@ class ASTNestedNameElement(ASTBase):
class ASTNestedName(ASTBase):
- def __init__(self, names, templates, rooted):
- # type: (List[ASTNestedNameElement], List[bool], bool) -> None
+ def __init__(self, names: List[ASTNestedNameElement],
+ templates: List[bool], rooted: bool) -> None:
assert len(names) > 0
self.names = names
self.templates = templates
@@ -2147,12 +1990,10 @@ class ASTNestedName(ASTBase):
self.rooted = rooted
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> "ASTNestedName":
return self
- def num_templates(self):
- # type: () -> int
+ def num_templates(self) -> int:
count = 0
for n in self.names:
if n.is_operator():
@@ -2161,8 +2002,7 @@ class ASTNestedName(ASTBase):
count += 1
return count
- def get_id(self, version, modifiers=''):
- # type: (int, str) -> str
+ def get_id(self, version: int, modifiers: str = '') -> str:
if version == 1:
tt = str(self)
if tt in _id_shorthands_v1:
@@ -2180,8 +2020,7 @@ class ASTNestedName(ASTBase):
res.append('E')
return ''.join(res)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
if self.rooted:
res.append('')
@@ -2194,8 +2033,8 @@ class ASTNestedName(ASTBase):
res.append(transform(n))
return '::'.join(res)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
# just print the name part, with template args, not template params
if mode == 'noneIsName':
@@ -2254,16 +2093,13 @@ class ASTNestedName(ASTBase):
class ASTTrailingTypeSpecFundamental(ASTBase):
- def __init__(self, name):
- # type: (str) -> None
+ def __init__(self, name: str) -> None:
self.name = name
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return self.name
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
if version == 1:
res = []
for a in self.name.split(' '):
@@ -2280,28 +2116,24 @@ class ASTTrailingTypeSpecFundamental(ASTBase):
'parser should have rejected it.' % self.name)
return _id_fundamental_v2[self.name]
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
signode += nodes.Text(str(self.name))
class ASTTrailingTypeSpecName(ASTBase):
- def __init__(self, prefix, nestedName):
- # type: (str, Any) -> None
+ def __init__(self, prefix: str, nestedName: Any) -> None:
self.prefix = prefix
self.nestedName = nestedName
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> ASTNestedName:
return self.nestedName
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
return self.nestedName.get_id(version)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
if self.prefix:
res.append(self.prefix)
@@ -2309,8 +2141,8 @@ class ASTTrailingTypeSpecName(ASTBase):
res.append(transform(self.nestedName))
return ''.join(res)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
if self.prefix:
signode += addnodes.desc_annotation(self.prefix, self.prefix)
signode += nodes.Text(' ')
@@ -2318,18 +2150,16 @@ class ASTTrailingTypeSpecName(ASTBase):
class ASTTrailingTypeSpecDecltypeAuto(ASTBase):
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return 'decltype(auto)'
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
if version == 1:
raise NoOldIdError()
return 'Dc'
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
signode.append(nodes.Text(str(self)))
@@ -2337,31 +2167,27 @@ class ASTTrailingTypeSpecDecltype(ASTBase):
def __init__(self, expr):
self.expr = expr
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return 'decltype(' + transform(self.expr) + ')'
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
if version == 1:
raise NoOldIdError()
return 'DT' + self.expr.get_id(version) + "E"
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
signode.append(nodes.Text('decltype('))
self.expr.describe_signature(signode, mode, env, symbol)
signode.append(nodes.Text(')'))
class ASTFunctionParameter(ASTBase):
- def __init__(self, arg, ellipsis=False):
- # type: (Any, bool) -> None
+ def __init__(self, arg: Any, ellipsis: bool = False) -> None:
self.arg = arg
self.ellipsis = ellipsis
- def get_id(self, version, objectType=None, symbol=None):
- # type: (int, str, Symbol) -> str
+ def get_id(self, version: int, objectType: str = None, symbol: "Symbol" = None) -> str:
# this is not part of the normal name mangling in C++
if symbol:
# the anchor will be our parent
@@ -2372,15 +2198,14 @@ class ASTFunctionParameter(ASTBase):
else:
return self.arg.get_id(version)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
if self.ellipsis:
return '...'
else:
return transform(self.arg)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
if self.ellipsis:
signode += nodes.Text('...')
@@ -2389,9 +2214,8 @@ class ASTFunctionParameter(ASTBase):
class ASTParametersQualifiers(ASTBase):
- def __init__(self, args, volatile, const, refQual, exceptionSpec, override,
- final, initializer):
- # type: (List[Any], bool, bool, str, str, bool, bool, str) -> None
+ def __init__(self, args: List[Any], volatile: bool, const: bool, refQual: str,
+ exceptionSpec: str, override: bool, final: bool, initializer: str) -> None:
self.args = args
self.volatile = volatile
self.const = const
@@ -2402,12 +2226,10 @@ class ASTParametersQualifiers(ASTBase):
self.initializer = initializer
@property
- def function_params(self):
- # type: () -> Any
+ def function_params(self) -> Any:
return self.args
- def get_modifiers_id(self, version):
- # type: (int) -> str
+ def get_modifiers_id(self, version: int) -> str:
res = []
if self.volatile:
res.append('V')
@@ -2422,8 +2244,7 @@ class ASTParametersQualifiers(ASTBase):
res.append('R')
return ''.join(res)
- def get_param_id(self, version):
- # type: (int) -> str
+ def get_param_id(self, version: int) -> str:
if version == 1:
if len(self.args) == 0:
return ''
@@ -2434,8 +2255,7 @@ class ASTParametersQualifiers(ASTBase):
else:
return ''.join(a.get_id(version) for a in self.args)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
res.append('(')
first = True
@@ -2464,8 +2284,8 @@ class ASTParametersQualifiers(ASTBase):
res.append(self.initializer)
return ''.join(res)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
paramlist = addnodes.desc_parameterlist()
for arg in self.args:
@@ -2501,9 +2321,9 @@ class ASTParametersQualifiers(ASTBase):
class ASTDeclSpecsSimple(ASTBase):
- def __init__(self, storage, threadLocal, inline, virtual, explicit,
- constexpr, volatile, const, friend, attrs):
- # type: (str, bool, bool, bool, bool, bool, bool, bool, bool, List[Any]) -> None
+ def __init__(self, storage: str, threadLocal: bool, inline: bool, virtual: bool,
+ explicit: bool, constexpr: bool, volatile: bool, const: bool,
+ friend: bool, attrs: List[Any]) -> None:
self.storage = storage
self.threadLocal = threadLocal
self.inline = inline
@@ -2515,8 +2335,7 @@ class ASTDeclSpecsSimple(ASTBase):
self.friend = friend
self.attrs = attrs
- def mergeWith(self, other):
- # type: (ASTDeclSpecsSimple) -> ASTDeclSpecsSimple
+ def mergeWith(self, other: "ASTDeclSpecsSimple") -> "ASTDeclSpecsSimple":
if not other:
return self
return ASTDeclSpecsSimple(self.storage or other.storage,
@@ -2530,8 +2349,7 @@ class ASTDeclSpecsSimple(ASTBase):
self.friend or other.friend,
self.attrs + other.attrs)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = [] # type: List[str]
res.extend(transform(attr) for attr in self.attrs)
if self.storage:
@@ -2554,8 +2372,7 @@ class ASTDeclSpecsSimple(ASTBase):
res.append('const')
return ' '.join(res)
- def describe_signature(self, modifiers):
- # type: (List[nodes.Node]) -> None
+ def describe_signature(self, modifiers: List[Node]) -> None:
def _add(modifiers, text):
if len(modifiers) > 0:
modifiers.append(nodes.Text(' '))
@@ -2585,8 +2402,8 @@ class ASTDeclSpecsSimple(ASTBase):
class ASTDeclSpecs(ASTBase):
- def __init__(self, outer, leftSpecs, rightSpecs, trailing):
- # type: (Any, ASTDeclSpecsSimple, ASTDeclSpecsSimple, Any) -> None
+ def __init__(self, outer: Any, leftSpecs: ASTDeclSpecsSimple,
+ rightSpecs: ASTDeclSpecsSimple, trailing: Any) -> None:
# leftSpecs and rightSpecs are used for output
# allSpecs are used for id generation
self.outer = outer
@@ -2596,12 +2413,10 @@ class ASTDeclSpecs(ASTBase):
self.trailingTypeSpec = trailing
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> ASTNestedName:
return self.trailingTypeSpec.name
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
if version == 1:
res = []
res.append(self.trailingTypeSpec.get_id(version))
@@ -2619,8 +2434,7 @@ class ASTDeclSpecs(ASTBase):
res.append(self.trailingTypeSpec.get_id(version))
return ''.join(res)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = [] # type: List[str]
l = transform(self.leftSpecs)
if len(l) > 0:
@@ -2636,8 +2450,8 @@ class ASTDeclSpecs(ASTBase):
res.append(r)
return "".join(res)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
modifiers = [] # type: List[nodes.Node]
@@ -2667,15 +2481,13 @@ class ASTArray(ASTBase):
def __init__(self, size):
self.size = size
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
if self.size:
return '[' + transform(self.size) + ']'
else:
return '[]'
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
if version == 1:
return 'A'
if version == 2:
@@ -2697,8 +2509,7 @@ class ASTArray(ASTBase):
class ASTDeclaratorPtr(ASTBase):
- def __init__(self, next, volatile, const, attrs):
- # type: (Any, bool, bool, Any) -> None
+ def __init__(self, next: Any, volatile: bool, const: bool, attrs: Any) -> None:
assert next
self.next = next
self.volatile = volatile
@@ -2706,22 +2517,18 @@ class ASTDeclaratorPtr(ASTBase):
self.attrs = attrs
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> ASTNestedName:
return self.next.name
@property
- def function_params(self):
- # type: () -> Any
+ def function_params(self) -> Any:
return self.next.function_params
- def require_space_after_declSpecs(self):
- # type: () -> bool
+ def require_space_after_declSpecs(self) -> bool:
# TODO: if has paramPack, then False ?
return True
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = ['*']
for a in self.attrs:
res.append(transform(a))
@@ -2739,16 +2546,13 @@ class ASTDeclaratorPtr(ASTBase):
res.append(transform(self.next))
return ''.join(res)
- def get_modifiers_id(self, version):
- # type: (int) -> str
+ def get_modifiers_id(self, version: int) -> str:
return self.next.get_modifiers_id(version)
- def get_param_id(self, version):
- # type: (int) -> str
+ def get_param_id(self, version: int) -> str:
return self.next.get_param_id(version)
- def get_ptr_suffix_id(self, version):
- # type: (int) -> str
+ def get_ptr_suffix_id(self, version: int) -> str:
if version == 1:
res = ['P']
if self.volatile:
@@ -2766,8 +2570,7 @@ class ASTDeclaratorPtr(ASTBase):
res.append('C')
return ''.join(res)
- def get_type_id(self, version, returnTypeId):
- # type: (int, str) -> str
+ def get_type_id(self, version: int, returnTypeId: str) -> str:
# ReturnType *next, so we are part of the return type of 'next
res = ['P']
if self.volatile:
@@ -2777,12 +2580,11 @@ class ASTDeclaratorPtr(ASTBase):
res.append(returnTypeId)
return self.next.get_type_id(version, returnTypeId=''.join(res))
- def is_function_type(self):
- # type: () -> bool
+ def is_function_type(self) -> bool:
return self.next.is_function_type()
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
signode += nodes.Text("*")
for a in self.attrs:
@@ -2805,33 +2607,27 @@ class ASTDeclaratorPtr(ASTBase):
class ASTDeclaratorRef(ASTBase):
- def __init__(self, next, attrs):
- # type: (Any, Any) -> None
+ def __init__(self, next: Any, attrs: Any) -> None:
assert next
self.next = next
self.attrs = attrs
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> ASTNestedName:
return self.next.name
@property
- def isPack(self):
- # type: () -> bool
+ def isPack(self) -> bool:
return True
@property
- def function_params(self):
- # type: () -> Any
+ def function_params(self) -> Any:
return self.next.function_params
- def require_space_after_declSpecs(self):
- # type: () -> bool
+ def require_space_after_declSpecs(self) -> bool:
return self.next.require_space_after_declSpecs()
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = ['&']
for a in self.attrs:
res.append(transform(a))
@@ -2840,33 +2636,28 @@ class ASTDeclaratorRef(ASTBase):
res.append(transform(self.next))
return ''.join(res)
- def get_modifiers_id(self, version):
- # type: (int) -> str
+ def get_modifiers_id(self, version: int) -> str:
return self.next.get_modifiers_id(version)
- def get_param_id(self, version): # only the parameters (if any)
- # type: (int) -> str
+ def get_param_id(self, version: int) -> str: # only the parameters (if any)
return self.next.get_param_id(version)
- def get_ptr_suffix_id(self, version):
- # type: (int) -> str
+ def get_ptr_suffix_id(self, version: int) -> str:
if version == 1:
return 'R' + self.next.get_ptr_suffix_id(version)
else:
return self.next.get_ptr_suffix_id(version) + 'R'
- def get_type_id(self, version, returnTypeId):
- # type: (int, str) -> str
+ def get_type_id(self, version: int, returnTypeId: str) -> str:
assert version >= 2
# ReturnType &next, so we are part of the return type of 'next
return self.next.get_type_id(version, returnTypeId='R' + returnTypeId)
- def is_function_type(self):
- # type: () -> bool
+ def is_function_type(self) -> bool:
return self.next.is_function_type()
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
signode += nodes.Text("&")
for a in self.attrs:
@@ -2877,59 +2668,49 @@ class ASTDeclaratorRef(ASTBase):
class ASTDeclaratorParamPack(ASTBase):
- def __init__(self, next):
- # type: (Any) -> None
+ def __init__(self, next: Any) -> None:
assert next
self.next = next
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> ASTNestedName:
return self.next.name
@property
- def function_params(self):
- # type: () -> Any
+ def function_params(self) -> Any:
return self.next.function_params
- def require_space_after_declSpecs(self):
- # type: () -> bool
+ def require_space_after_declSpecs(self) -> bool:
return False
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = transform(self.next)
if self.next.name:
res = ' ' + res
return '...' + res
- def get_modifiers_id(self, version):
- # type: (int) -> str
+ def get_modifiers_id(self, version: int) -> str:
return self.next.get_modifiers_id(version)
- def get_param_id(self, version): # only the parameters (if any)
- # type: (int) -> str
+ def get_param_id(self, version: int) -> str: # only the parameters (if any)
return self.next.get_param_id(version)
- def get_ptr_suffix_id(self, version):
- # type: (int) -> str
+ def get_ptr_suffix_id(self, version: int) -> str:
if version == 1:
return 'Dp' + self.next.get_ptr_suffix_id(version)
else:
return self.next.get_ptr_suffix_id(version) + 'Dp'
- def get_type_id(self, version, returnTypeId):
- # type: (int, str) -> str
+ def get_type_id(self, version: int, returnTypeId: str) -> str:
assert version >= 2
# ReturnType... next, so we are part of the return type of 'next
return self.next.get_type_id(version, returnTypeId='Dp' + returnTypeId)
- def is_function_type(self):
- # type: () -> bool
+ def is_function_type(self) -> bool:
return self.next.is_function_type()
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
signode += nodes.Text("...")
if self.next.name:
@@ -2938,8 +2719,7 @@ class ASTDeclaratorParamPack(ASTBase):
class ASTDeclaratorMemPtr(ASTBase):
- def __init__(self, className, const, volatile, next):
- # type: (Any, bool, bool, Any) -> None
+ def __init__(self, className: Any, const: bool, volatile: bool, next: Any) -> None:
assert className
assert next
self.className = className
@@ -2948,21 +2728,17 @@ class ASTDeclaratorMemPtr(ASTBase):
self.next = next
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> ASTNestedName:
return self.next.name
@property
- def function_params(self):
- # type: () -> Any
+ def function_params(self) -> Any:
return self.next.function_params
- def require_space_after_declSpecs(self):
- # type: () -> bool
+ def require_space_after_declSpecs(self) -> bool:
return True
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
res.append(transform(self.className))
res.append('::*')
@@ -2975,30 +2751,26 @@ class ASTDeclaratorMemPtr(ASTBase):
res.append(transform(self.next))
return ''.join(res)
- def get_modifiers_id(self, version):
- # type: (int) -> str
+ def get_modifiers_id(self, version: int) -> str:
if version == 1:
raise NoOldIdError()
else:
return self.next.get_modifiers_id(version)
- def get_param_id(self, version): # only the parameters (if any)
- # type: (int) -> str
+ def get_param_id(self, version: int) -> str: # only the parameters (if any)
if version == 1:
raise NoOldIdError()
else:
return self.next.get_param_id(version)
- def get_ptr_suffix_id(self, version):
- # type: (int) -> str
+ def get_ptr_suffix_id(self, version: int) -> str:
if version == 1:
raise NoOldIdError()
else:
raise NotImplementedError()
return self.next.get_ptr_suffix_id(version) + 'Dp'
- def get_type_id(self, version, returnTypeId):
- # type: (int, str) -> str
+ def get_type_id(self, version: int, returnTypeId: str) -> str:
assert version >= 2
# ReturnType name::* next, so we are part of the return type of next
nextReturnTypeId = ''
@@ -3011,12 +2783,11 @@ class ASTDeclaratorMemPtr(ASTBase):
nextReturnTypeId += returnTypeId
return self.next.get_type_id(version, nextReturnTypeId)
- def is_function_type(self):
- # type: () -> bool
+ def is_function_type(self) -> bool:
return self.next.is_function_type()
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
self.className.describe_signature(signode, mode, env, symbol)
signode += nodes.Text('::*')
@@ -3036,8 +2807,7 @@ class ASTDeclaratorMemPtr(ASTBase):
class ASTDeclaratorParen(ASTBase):
- def __init__(self, inner, next):
- # type: (Any, Any) -> None
+ def __init__(self, inner: Any, next: Any) -> None:
assert inner
assert next
self.inner = inner
@@ -3045,37 +2815,30 @@ class ASTDeclaratorParen(ASTBase):
# TODO: we assume the name, params, and qualifiers are in inner
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> ASTNestedName:
return self.inner.name
@property
- def function_params(self):
- # type: () -> Any
+ def function_params(self) -> Any:
return self.inner.function_params
- def require_space_after_declSpecs(self):
- # type: () -> bool
+ def require_space_after_declSpecs(self) -> bool:
return True
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = ['(']
res.append(transform(self.inner))
res.append(')')
res.append(transform(self.next))
return ''.join(res)
- def get_modifiers_id(self, version):
- # type: (int) -> str
+ def get_modifiers_id(self, version: int) -> str:
return self.inner.get_modifiers_id(version)
- def get_param_id(self, version): # only the parameters (if any)
- # type: (int) -> str
+ def get_param_id(self, version: int) -> str: # only the parameters (if any)
return self.inner.get_param_id(version)
- def get_ptr_suffix_id(self, version):
- # type: (int) -> str
+ def get_ptr_suffix_id(self, version: int) -> str:
if version == 1:
raise NoOldIdError() # TODO: was this implemented before?
return self.next.get_ptr_suffix_id(version) + \
@@ -3084,19 +2847,17 @@ class ASTDeclaratorParen(ASTBase):
return self.inner.get_ptr_suffix_id(version) + \
self.next.get_ptr_suffix_id(version)
- def get_type_id(self, version, returnTypeId):
- # type: (int, str) -> str
+ def get_type_id(self, version: int, returnTypeId: str) -> str:
assert version >= 2
# ReturnType (inner)next, so 'inner' returns everything outside
nextId = self.next.get_type_id(version, returnTypeId)
return self.inner.get_type_id(version, returnTypeId=nextId)
- def is_function_type(self):
- # type: () -> bool
+ def is_function_type(self) -> bool:
return self.inner.is_function_type()
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
signode += nodes.Text('(')
self.inner.describe_signature(signode, mode, env, symbol)
@@ -3105,47 +2866,40 @@ class ASTDeclaratorParen(ASTBase):
class ASTDeclaratorNameParamQual(ASTBase):
- def __init__(self, declId, arrayOps, paramQual):
- # type: (Any, List[Any], Any) -> None
+ def __init__(self, declId: Any, arrayOps: List[Any], paramQual: Any) -> None:
self.declId = declId
self.arrayOps = arrayOps
self.paramQual = paramQual
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> ASTNestedName:
return self.declId
@property
- def isPack(self):
- # type: () -> bool
+ def isPack(self) -> bool:
return False
@property
- def function_params(self):
- # type: () -> Any
+ def function_params(self) -> Any:
return self.paramQual.function_params
- def get_modifiers_id(self, version): # only the modifiers for a function, e.g.,
- # type: (int) -> str
+ # only the modifiers for a function, e.g.,
+ def get_modifiers_id(self, version: int) -> str:
# cv-qualifiers
if self.paramQual:
return self.paramQual.get_modifiers_id(version)
raise Exception("This should only be called on a function: %s" % self)
- def get_param_id(self, version): # only the parameters (if any)
- # type: (int) -> str
+ def get_param_id(self, version: int) -> str: # only the parameters (if any)
if self.paramQual:
return self.paramQual.get_param_id(version)
else:
return ''
- def get_ptr_suffix_id(self, version): # only the array specifiers
- # type: (int) -> str
+ def get_ptr_suffix_id(self, version: int) -> str: # only the array specifiers
return ''.join(a.get_id(version) for a in self.arrayOps)
- def get_type_id(self, version, returnTypeId):
- # type: (int, str) -> str
+ def get_type_id(self, version: int, returnTypeId: str) -> str:
assert version >= 2
res = []
# TOOD: can we actually have both array ops and paramQual?
@@ -3162,16 +2916,13 @@ class ASTDeclaratorNameParamQual(ASTBase):
# ------------------------------------------------------------------------
- def require_space_after_declSpecs(self):
- # type: () -> bool
+ def require_space_after_declSpecs(self) -> bool:
return self.declId is not None
- def is_function_type(self):
- # type: () -> bool
+ def is_function_type(self) -> bool:
return self.paramQual is not None
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
if self.declId:
res.append(transform(self.declId))
@@ -3181,8 +2932,8 @@ class ASTDeclaratorNameParamQual(ASTBase):
res.append(transform(self.paramQual))
return ''.join(res)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
if self.declId:
self.declId.describe_signature(signode, mode, env, symbol)
@@ -3198,30 +2949,24 @@ class ASTDeclaratorNameBitField(ASTBase):
self.size = size
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> ASTNestedName:
return self.declId
- def get_param_id(self, version): # only the parameters (if any)
- # type: (int) -> str
+ def get_param_id(self, version: int) -> str: # only the parameters (if any)
return ''
- def get_ptr_suffix_id(self, version): # only the array specifiers
- # type: (int) -> str
+ def get_ptr_suffix_id(self, version: int) -> str: # only the array specifiers
return ''
# ------------------------------------------------------------------------
- def require_space_after_declSpecs(self):
- # type: () -> bool
+ def require_space_after_declSpecs(self) -> bool:
return self.declId is not None
- def is_function_type(self):
- # type: () -> bool
+ def is_function_type(self) -> bool:
return False
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
if self.declId:
res.append(transform(self.declId))
@@ -3229,8 +2974,8 @@ class ASTDeclaratorNameBitField(ASTBase):
res.append(transform(self.size))
return ''.join(res)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
if self.declId:
self.declId.describe_signature(signode, mode, env, symbol)
@@ -3239,21 +2984,18 @@ class ASTDeclaratorNameBitField(ASTBase):
class ASTParenExprList(ASTBase):
- def __init__(self, exprs):
- # type: (List[Any]) -> None
+ def __init__(self, exprs: List[Any]) -> None:
self.exprs = exprs
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
return "pi%sE" % ''.join(e.get_id(version) for e in self.exprs)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
exprs = [transform(e) for e in self.exprs]
return '(%s)' % ', '.join(exprs)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
signode.append(nodes.Text('('))
first = True
@@ -3267,23 +3009,20 @@ class ASTParenExprList(ASTBase):
class ASTBracedInitList(ASTBase):
- def __init__(self, exprs, trailingComma):
- # type: (List[Any], bool) -> None
+ def __init__(self, exprs: List[Any], trailingComma: bool) -> None:
self.exprs = exprs
self.trailingComma = trailingComma
- def get_id(self, version):
- # type: (int) -> str
+ def get_id(self, version: int) -> str:
return "il%sE" % ''.join(e.get_id(version) for e in self.exprs)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
exprs = [transform(e) for e in self.exprs]
trailingComma = ',' if self.trailingComma else ''
return '{%s%s}' % (', '.join(exprs), trailingComma)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
signode.append(nodes.Text('{'))
first = True
@@ -3299,21 +3038,19 @@ class ASTBracedInitList(ASTBase):
class ASTInitializer(ASTBase):
- def __init__(self, value, hasAssign=True):
- # type: (Any, bool) -> None
+ def __init__(self, value: Any, hasAssign: bool = True) -> None:
self.value = value
self.hasAssign = hasAssign
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
val = transform(self.value)
if self.hasAssign:
return ' = ' + val
else:
return val
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
if self.hasAssign:
signode.append(nodes.Text(' = '))
@@ -3321,30 +3058,26 @@ class ASTInitializer(ASTBase):
class ASTType(ASTBase):
- def __init__(self, declSpecs, decl):
- # type: (Any, Any) -> None
+ def __init__(self, declSpecs: Any, decl: Any) -> None:
assert declSpecs
assert decl
self.declSpecs = declSpecs
self.decl = decl
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> ASTNestedName:
return self.decl.name
@property
- def isPack(self):
- # type: () -> bool
+ def isPack(self) -> bool:
return self.decl.isPack
@property
- def function_params(self):
- # type: () -> Any
+ def function_params(self) -> Any:
return self.decl.function_params
- def get_id(self, version, objectType=None, symbol=None):
- # type: (int, str, Symbol) -> str
+ def get_id(self, version: int, objectType: str = None,
+ symbol: "Symbol" = None) -> str:
if version == 1:
res = []
if objectType: # needs the name
@@ -3396,8 +3129,7 @@ class ASTType(ASTBase):
res.append(typeId)
return ''.join(res)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
declSpecs = transform(self.declSpecs)
res.append(declSpecs)
@@ -3406,15 +3138,14 @@ class ASTType(ASTBase):
res.append(transform(self.decl))
return ''.join(res)
- def get_type_declaration_prefix(self):
- # type: () -> str
+ def get_type_declaration_prefix(self) -> str:
if self.declSpecs.trailingTypeSpec:
return 'typedef'
else:
return 'type'
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
self.declSpecs.describe_signature(signode, 'markType', env, symbol)
if (self.decl.require_space_after_declSpecs() and
@@ -3428,23 +3159,20 @@ class ASTType(ASTBase):
class ASTTypeWithInit(ASTBase):
- def __init__(self, type, init):
- # type: (Any, Any) -> None
+ def __init__(self, type: Any, init: Any) -> None:
self.type = type
self.init = init
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> ASTNestedName:
return self.type.name
@property
- def isPack(self):
- # type: () -> bool
+ def isPack(self) -> bool:
return self.type.isPack
- def get_id(self, version, objectType=None, symbol=None):
- # type: (int, str, Symbol) -> str
+ def get_id(self, version: int, objectType: str = None,
+ symbol: "Symbol" = None) -> str:
if objectType != 'member':
return self.type.get_id(version, objectType)
if version == 1:
@@ -3452,16 +3180,15 @@ class ASTTypeWithInit(ASTBase):
self.type.get_id(version))
return symbol.get_full_nested_name().get_id(version)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
res.append(transform(self.type))
if self.init:
res.append(transform(self.init))
return ''.join(res)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
self.type.describe_signature(signode, mode, env, symbol)
if self.init:
@@ -3469,19 +3196,17 @@ class ASTTypeWithInit(ASTBase):
class ASTTypeUsing(ASTBase):
- def __init__(self, name, type):
- # type: (Any, Any) -> None
+ def __init__(self, name: Any, type: Any) -> None:
self.name = name
self.type = type
- def get_id(self, version, objectType=None, symbol=None):
- # type: (int, str, Symbol) -> str
+ def get_id(self, version: int, objectType: str = None,
+ symbol: "Symbol" = None) -> str:
if version == 1:
raise NoOldIdError()
return symbol.get_full_nested_name().get_id(version)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
res.append(transform(self.name))
if self.type:
@@ -3489,12 +3214,11 @@ class ASTTypeUsing(ASTBase):
res.append(transform(self.type))
return ''.join(res)
- def get_type_declaration_prefix(self):
- # type: () -> str
+ def get_type_declaration_prefix(self) -> str:
return 'using'
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
self.name.describe_signature(signode, mode, env, symbol=symbol)
if self.type:
@@ -3503,46 +3227,42 @@ class ASTTypeUsing(ASTBase):
class ASTConcept(ASTBase):
- def __init__(self, nestedName, initializer):
- # type: (Any, Any) -> None
+ def __init__(self, nestedName: Any, initializer: Any) -> None:
self.nestedName = nestedName
self.initializer = initializer
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> ASTNestedName:
return self.nestedName
- def get_id(self, version, objectType=None, symbol=None):
- # type: (int, str, Symbol) -> str
+ def get_id(self, version: int, objectType: str = None,
+ symbol: "Symbol" = None) -> str:
if version == 1:
raise NoOldIdError()
return symbol.get_full_nested_name().get_id(version)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = transform(self.nestedName)
if self.initializer:
res += transform(self.initializer)
return res
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
self.nestedName.describe_signature(signode, mode, env, symbol)
if self.initializer:
self.initializer.describe_signature(signode, mode, env, symbol)
class ASTBaseClass(ASTBase):
- def __init__(self, name, visibility, virtual, pack):
- # type: (ASTNestedName, str, bool, bool) -> None
+ def __init__(self, name: ASTNestedName, visibility: str,
+ virtual: bool, pack: bool) -> None:
self.name = name
self.visibility = visibility
self.virtual = virtual
self.pack = pack
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
if self.visibility is not None:
@@ -3555,8 +3275,8 @@ class ASTBaseClass(ASTBase):
res.append('...')
return ''.join(res)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
if self.visibility is not None:
signode += addnodes.desc_annotation(self.visibility,
@@ -3571,18 +3291,15 @@ class ASTBaseClass(ASTBase):
class ASTClass(ASTBase):
- def __init__(self, name, final, bases):
- # type: (ASTNestedName, bool, List[ASTBaseClass]) -> None
+ def __init__(self, name: ASTNestedName, final: bool, bases: List[ASTBaseClass]) -> None:
self.name = name
self.final = final
self.bases = bases
- def get_id(self, version, objectType, symbol):
- # type: (int, str, Symbol) -> str
+ def get_id(self, version: int, objectType: str, symbol: "Symbol") -> str:
return symbol.get_full_nested_name().get_id(version)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
res.append(transform(self.name))
if self.final:
@@ -3597,8 +3314,8 @@ class ASTClass(ASTBase):
res.append(transform(b))
return ''.join(res)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
self.name.describe_signature(signode, mode, env, symbol=symbol)
if self.final:
@@ -3613,41 +3330,35 @@ class ASTClass(ASTBase):
class ASTUnion(ASTBase):
- def __init__(self, name):
- # type: (Any) -> None
+ def __init__(self, name: Any) -> None:
self.name = name
- def get_id(self, version, objectType, symbol):
- # type: (int, str, Symbol) -> str
+ def get_id(self, version: int, objectType: str, symbol: "Symbol") -> str:
if version == 1:
raise NoOldIdError()
return symbol.get_full_nested_name().get_id(version)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
return transform(self.name)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
self.name.describe_signature(signode, mode, env, symbol=symbol)
class ASTEnum(ASTBase):
- def __init__(self, name, scoped, underlyingType):
- # type: (Any, str, Any) -> None
+ def __init__(self, name: Any, scoped: str, underlyingType: Any) -> None:
self.name = name
self.scoped = scoped
self.underlyingType = underlyingType
- def get_id(self, version, objectType, symbol):
- # type: (int, str, Symbol) -> str
+ def get_id(self, version: int, objectType: str, symbol: "Symbol") -> str:
if version == 1:
raise NoOldIdError()
return symbol.get_full_nested_name().get_id(version)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
if self.scoped:
res.append(self.scoped)
@@ -3658,8 +3369,8 @@ class ASTEnum(ASTBase):
res.append(transform(self.underlyingType))
return ''.join(res)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
# self.scoped has been done by the CPPEnumObject
self.name.describe_signature(signode, mode, env, symbol=symbol)
@@ -3670,27 +3381,24 @@ class ASTEnum(ASTBase):
class ASTEnumerator(ASTBase):
- def __init__(self, name, init):
- # type: (Any, Any) -> None
+ def __init__(self, name: Any, init: Any) -> None:
self.name = name
self.init = init
- def get_id(self, version, objectType, symbol):
- # type: (int, str, Symbol) -> str
+ def get_id(self, version: int, objectType: str, symbol: "Symbol") -> str:
if version == 1:
raise NoOldIdError()
return symbol.get_full_nested_name().get_id(version)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
res.append(transform(self.name))
if self.init:
res.append(transform(self.init))
return ''.join(res)
- def describe_signature(self, signode, mode, env, symbol):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
_verify_description_mode(mode)
self.name.describe_signature(signode, mode, env, symbol)
if self.init:
@@ -3698,8 +3406,8 @@ class ASTEnumerator(ASTBase):
class ASTDeclaration(ASTBase):
- def __init__(self, objectType, directiveType, visibility, templatePrefix, declaration):
- # type: (str, str, str, ASTTemplateDeclarationPrefix, Any) -> None
+ def __init__(self, objectType: str, directiveType: str, visibility: str,
+ templatePrefix: ASTTemplateDeclarationPrefix, declaration: Any) -> None:
self.objectType = objectType
self.directiveType = directiveType
self.visibility = visibility
@@ -3710,8 +3418,7 @@ class ASTDeclaration(ASTBase):
# set by CPPObject._add_enumerator_to_parent
self.enumeratorScopedSymbol = None # type: Symbol
- def clone(self):
- # type: () -> ASTDeclaration
+ def clone(self) -> "ASTDeclaration":
if self.templatePrefix:
templatePrefixClone = self.templatePrefix.clone()
else:
@@ -3721,19 +3428,16 @@ class ASTDeclaration(ASTBase):
self.declaration.clone())
@property
- def name(self):
- # type: () -> ASTNestedName
+ def name(self) -> ASTNestedName:
return self.declaration.name
@property
- def function_params(self):
- # type: () -> Any
+ def function_params(self) -> Any:
if self.objectType != 'function':
return None
return self.declaration.function_params
- def get_id(self, version, prefixed=True):
- # type: (int, bool) -> str
+ def get_id(self, version: int, prefixed: bool = True) -> str:
if version == 1:
if self.templatePrefix:
raise NoOldIdError()
@@ -3752,12 +3456,10 @@ class ASTDeclaration(ASTBase):
res.append(self.declaration.get_id(version, self.objectType, self.symbol))
return ''.join(res)
- def get_newest_id(self):
- # type: () -> str
+ def get_newest_id(self) -> str:
return self.get_id(_max_id, True)
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
if self.visibility and self.visibility != "public":
res.append(self.visibility)
@@ -3767,8 +3469,8 @@ class ASTDeclaration(ASTBase):
res.append(transform(self.declaration))
return ''.join(res)
- def describe_signature(self, signode, mode, env, options):
- # type: (addnodes.desc_signature, str, BuildEnvironment, Dict) -> None
+ def describe_signature(self, signode: desc_signature, mode: str,
+ env: "BuildEnvironment", options: Dict) -> None:
_verify_description_mode(mode)
assert self.symbol
# The caller of the domain added a desc_signature node.
@@ -3821,13 +3523,12 @@ class ASTDeclaration(ASTBase):
class ASTNamespace(ASTBase):
- def __init__(self, nestedName, templatePrefix):
- # type: (ASTNestedName, ASTTemplateDeclarationPrefix) -> None
+ def __init__(self, nestedName: ASTNestedName,
+ templatePrefix: ASTTemplateDeclarationPrefix) -> None:
self.nestedName = nestedName
self.templatePrefix = templatePrefix
- def _stringify(self, transform):
- # type: (Callable[[Any], str]) -> str
+ def _stringify(self, transform: StringifyTransform) -> str:
res = []
if self.templatePrefix:
res.append(transform(self.templatePrefix))
@@ -3836,8 +3537,9 @@ class ASTNamespace(ASTBase):
class SymbolLookupResult:
- def __init__(self, symbols, parentSymbol, identOrOp, templateParams, templateArgs):
- # type: (Iterator[Symbol], Symbol, Union[ASTIdentifier, ASTOperator], Any, ASTTemplateArgs) -> None # NOQA
+ def __init__(self, symbols: Iterator["Symbol"], parentSymbol: "Symbol",
+ identOrOp: Union[ASTIdentifier, ASTOperator], templateParams: Any,
+ templateArgs: ASTTemplateArgs) -> None:
self.symbols = symbols
self.parentSymbol = parentSymbol
self.identOrOp = identOrOp
@@ -3849,8 +3551,7 @@ class Symbol:
debug_lookup = False
debug_show_tree = False
- def _assert_invariants(self):
- # type: () -> None
+ def _assert_invariants(self) -> None:
if not self.parent:
# parent == None means global scope, so declaration means a parent
assert not self.identOrOp
@@ -3868,15 +3569,9 @@ class Symbol:
else:
return super().__setattr__(key, value)
- def __init__(self,
- parent, # type: Symbol
- identOrOp, # type: Union[ASTIdentifier, ASTOperator]
- templateParams, # type: Any
- templateArgs, # type: Any
- declaration, # type: ASTDeclaration
- docname # type: str
- ):
- # type: (...) -> None
+ def __init__(self, parent: "Symbol", identOrOp: Union[ASTIdentifier, ASTOperator],
+ templateParams: Any, templateArgs: Any, declaration: ASTDeclaration,
+ docname: str) -> None:
self.parent = parent
self.identOrOp = identOrOp
self.templateParams = templateParams # template<templateParams>
@@ -3898,8 +3593,7 @@ class Symbol:
# Do symbol addition after self._children has been initialised.
self._add_template_and_function_params()
- def _fill_empty(self, declaration, docname):
- # type: (ASTDeclaration, str) -> None
+ def _fill_empty(self, declaration: ASTDeclaration, docname: str) -> None:
self._assert_invariants()
assert not self.declaration
assert not self.docname
@@ -3950,8 +3644,7 @@ class Symbol:
self.parent._children.remove(self)
self.parent = None
- def clear_doc(self, docname):
- # type: (str) -> None
+ def clear_doc(self, docname: str) -> None:
newChildren = []
for sChild in self._children:
sChild.clear_doc(docname)
@@ -3961,8 +3654,7 @@ class Symbol:
newChildren.append(sChild)
self._children = newChildren
- def get_all_symbols(self):
- # type: () -> Iterator[Any]
+ def get_all_symbols(self) -> Iterator[Any]:
yield self
for sChild in self._children:
for s in sChild.get_all_symbols():
@@ -3977,8 +3669,7 @@ class Symbol:
yield from c.children_recurse_anon
- def get_lookup_key(self):
- # type: () -> List[Tuple[ASTNestedNameElement, Any]]
+ def get_lookup_key(self) -> List[Tuple[ASTNestedNameElement, Any]]:
symbols = []
s = self
while s.parent:
@@ -3991,8 +3682,7 @@ class Symbol:
key.append((nne, s.templateParams))
return key
- def get_full_nested_name(self):
- # type: () -> ASTNestedName
+ def get_full_nested_name(self) -> ASTNestedName:
names = []
templates = []
for nne, templateParams in self.get_lookup_key():
@@ -4000,17 +3690,11 @@ class Symbol:
templates.append(False)
return ASTNestedName(names, templates, rooted=False)
- def _find_first_named_symbol(
- self,
- identOrOp, # type: Union[ASTIdentifier, ASTOperator]
- templateParams, # type: Any
- templateArgs, # type: ASTTemplateArgs
- templateShorthand, # type: bool
- matchSelf, # type: bool
- recurseInAnon, # type: bool
- correctPrimaryTemplateArgs # type: bool
- ): # NOQA
- # type: (...) -> Symbol
+ def _find_first_named_symbol(self, identOrOp: Union[ASTIdentifier, ASTOperator],
+ templateParams: Any, templateArgs: ASTTemplateArgs,
+ templateShorthand: bool, matchSelf: bool,
+ recurseInAnon: bool, correctPrimaryTemplateArgs: bool
+ ) -> "Symbol":
res = self._find_named_symbols(identOrOp, templateParams, templateArgs,
templateShorthand, matchSelf, recurseInAnon,
correctPrimaryTemplateArgs)
@@ -4019,16 +3703,11 @@ class Symbol:
except StopIteration:
return None
- def _find_named_symbols(self,
- identOrOp, # type: Union[ASTIdentifier, ASTOperator]
- templateParams, # type: Any
- templateArgs, # type: ASTTemplateArgs
- templateShorthand, # type: bool
- matchSelf, # type: bool
- recurseInAnon, # type: bool
- correctPrimaryTemplateArgs # type: bool
- ):
- # type: (...) -> Iterator[Symbol]
+ def _find_named_symbols(self, identOrOp: Union[ASTIdentifier, ASTOperator],
+ templateParams: Any, templateArgs: ASTTemplateArgs,
+ templateShorthand: bool, matchSelf: bool,
+ recurseInAnon: bool, correctPrimaryTemplateArgs: bool
+ ) -> Iterator["Symbol"]:
def isSpecialization():
# the names of the template parameters must be given exactly as args
@@ -4087,20 +3766,12 @@ class Symbol:
if matches(s):
yield s
- def _symbol_lookup(
- self,
- nestedName, # type: ASTNestedName
- templateDecls, # type: List[Any]
- onMissingQualifiedSymbol,
- # type: Callable[[Symbol, Union[ASTIdentifier, ASTOperator], Any, ASTTemplateArgs], Symbol] # NOQA
- strictTemplateParamArgLists, # type: bool
- ancestorLookupType, # type: str
- templateShorthand, # type: bool
- matchSelf, # type: bool
- recurseInAnon, # type: bool
- correctPrimaryTemplateArgs # type: bool
- ):
- # type: (...) -> SymbolLookupResult
+ def _symbol_lookup(self, nestedName: ASTNestedName, templateDecls: List[Any],
+ onMissingQualifiedSymbol: Callable[["Symbol", Union[ASTIdentifier, ASTOperator], Any, ASTTemplateArgs], "Symbol"], # NOQA
+ strictTemplateParamArgLists: bool, ancestorLookupType: str,
+ templateShorthand: bool, matchSelf: bool,
+ recurseInAnon: bool, correctPrimaryTemplateArgs: bool
+ ) -> SymbolLookupResult:
# ancestorLookupType: if not None, specifies the target type of the lookup
if strictTemplateParamArgLists:
@@ -4194,8 +3865,8 @@ class Symbol:
return SymbolLookupResult(symbols, parentSymbol,
identOrOp, templateParams, templateArgs)
- def _add_symbols(self, nestedName, templateDecls, declaration, docname):
- # type: (ASTNestedName, List[Any], ASTDeclaration, str) -> Symbol
+ def _add_symbols(self, nestedName: ASTNestedName, templateDecls: List[Any],
+ declaration: ASTDeclaration, docname: str) -> "Symbol":
# Used for adding a whole path of symbols, where the last may or may not
# be an actual declaration.
@@ -4206,8 +3877,10 @@ class Symbol:
print(" decl: ", declaration)
print(" doc: ", docname)
- def onMissingQualifiedSymbol(parentSymbol, identOrOp, templateParams, templateArgs):
- # type: (Symbol, Union[ASTIdentifier, ASTOperator], Any, ASTTemplateArgs) -> Symbol
+ def onMissingQualifiedSymbol(parentSymbol: "Symbol",
+ identOrOp: Union[ASTIdentifier, ASTOperator],
+ templateParams: Any, templateArgs: ASTTemplateArgs
+ ) -> "Symbol":
if Symbol.debug_lookup:
print(" _add_symbols, onMissingQualifiedSymbol:")
print(" templateParams:", templateParams)
@@ -4346,8 +4019,8 @@ class Symbol:
symbol._fill_empty(declaration, docname)
return symbol
- def merge_with(self, other, docnames, env):
- # type: (Symbol, List[str], BuildEnvironment) -> None
+ def merge_with(self, other: "Symbol", docnames: List[str],
+ env: "BuildEnvironment") -> None:
assert other is not None
for otherChild in other._children:
ourChild = self._find_first_named_symbol(
@@ -4378,8 +4051,8 @@ class Symbol:
pass
ourChild.merge_with(otherChild, docnames, env)
- def add_name(self, nestedName, templatePrefix=None):
- # type: (ASTNestedName, ASTTemplateDeclarationPrefix) -> Symbol
+ def add_name(self, nestedName: ASTNestedName,
+ templatePrefix: ASTTemplateDeclarationPrefix = None) -> "Symbol":
if templatePrefix:
templateDecls = templatePrefix.templates
else:
@@ -4387,8 +4060,7 @@ class Symbol:
return self._add_symbols(nestedName, templateDecls,
declaration=None, docname=None)
- def add_declaration(self, declaration, docname):
- # type: (ASTDeclaration, str) -> Symbol
+ def add_declaration(self, declaration: ASTDeclaration, docname: str) -> "Symbol":
assert declaration
assert docname
nestedName = declaration.name
@@ -4398,8 +4070,8 @@ class Symbol:
templateDecls = []
return self._add_symbols(nestedName, templateDecls, declaration, docname)
- def find_identifier(self, identOrOp, matchSelf, recurseInAnon):
- # type: (Union[ASTIdentifier, ASTOperator], bool, bool) -> Symbol
+ def find_identifier(self, identOrOp: Union[ASTIdentifier, ASTOperator],
+ matchSelf: bool, recurseInAnon: bool) -> "Symbol":
if matchSelf and self.identOrOp == identOrOp:
return self
children = self.children_recurse_anon if recurseInAnon else self._children
@@ -4408,8 +4080,7 @@ class Symbol:
return s
return None
- def direct_lookup(self, key):
- # type: (List[Tuple[ASTNestedNameElement, Any]]) -> Symbol
+ def direct_lookup(self, key: List[Tuple[ASTNestedNameElement, Any]]) -> "Symbol":
s = self
for name, templateParams in key:
identOrOp = name.identOrOp
@@ -4424,13 +4095,15 @@ class Symbol:
return None
return s
- def find_name(self, nestedName, templateDecls, typ, templateShorthand,
- matchSelf, recurseInAnon):
- # type: (ASTNestedName, List[Any], str, bool, bool, bool) -> List[Symbol]
+ def find_name(self, nestedName: ASTNestedName, templateDecls: List[Any],
+ typ: str, templateShorthand: bool, matchSelf: bool,
+ recurseInAnon: bool) -> List["Symbol"]:
# templateShorthand: missing template parameter lists for templates is ok
- def onMissingQualifiedSymbol(parentSymbol, identOrOp, templateParams, templateArgs):
- # type: (Symbol, Union[ASTIdentifier, ASTOperator], Any, ASTTemplateArgs) -> Symbol
+ def onMissingQualifiedSymbol(parentSymbol: "Symbol",
+ identOrOp: Union[ASTIdentifier, ASTOperator],
+ templateParams: Any,
+ templateArgs: ASTTemplateArgs) -> "Symbol":
# TODO: Maybe search without template args?
# Though, the correctPrimaryTemplateArgs does
# that for primary templates.
@@ -4463,9 +4136,8 @@ class Symbol:
else:
return None
- def find_declaration(self, declaration, typ, templateShorthand,
- matchSelf, recurseInAnon):
- # type: (ASTDeclaration, str, bool, bool, bool) -> Symbol
+ def find_declaration(self, declaration: ASTDeclaration, typ: str, templateShorthand: bool,
+ matchSelf: bool, recurseInAnon: bool) -> "Symbol":
# templateShorthand: missing template parameter lists for templates is ok
nestedName = declaration.name
if declaration.templatePrefix:
@@ -4473,8 +4145,10 @@ class Symbol:
else:
templateDecls = []
- def onMissingQualifiedSymbol(parentSymbol, identOrOp, templateParams, templateArgs):
- # type: (Symbol, Union[ASTIdentifier, ASTOperator], Any, ASTTemplateArgs) -> Symbol
+ def onMissingQualifiedSymbol(parentSymbol: "Symbol",
+ identOrOp: Union[ASTIdentifier, ASTOperator],
+ templateParams: Any,
+ templateArgs: ASTTemplateArgs) -> "Symbol":
return None
lookupResult = self._symbol_lookup(nestedName, templateDecls,
@@ -4510,8 +4184,7 @@ class Symbol:
querySymbol.remove()
return None
- def to_string(self, indent):
- # type: (int) -> str
+ def to_string(self, indent: int) -> str:
res = ['\t' * indent]
if not self.parent:
res.append('::')
@@ -4538,8 +4211,7 @@ class Symbol:
res.append('\n')
return ''.join(res)
- def dump(self, indent):
- # type: (int) -> str
+ def dump(self, indent: int) -> str:
res = [self.to_string(indent)]
for c in self._children:
res.append(c.dump(indent + 1))
@@ -4556,8 +4228,7 @@ class DefinitionParser:
_prefix_keys = ('class', 'struct', 'enum', 'union', 'typename')
- def __init__(self, definition, warnEnv, config):
- # type: (Any, Any, Config) -> None
+ def __init__(self, definition: Any, warnEnv: Any, config: "Config") -> None:
self.definition = definition.strip()
self.pos = 0
self.end = len(self.definition)
@@ -4570,8 +4241,7 @@ class DefinitionParser:
self.warnEnv = warnEnv
self.config = config
- def _make_multi_error(self, errors, header):
- # type: (List[Any], str) -> DefinitionError
+ def _make_multi_error(self, errors: List[Any], header: str) -> DefinitionError:
if len(errors) == 1:
if len(header) > 0:
return DefinitionError(header + '\n' + str(errors[0][0]))
@@ -4593,14 +4263,12 @@ class DefinitionParser:
result.append(str(e[0]))
return DefinitionError(''.join(result))
- def status(self, msg):
- # type: (str) -> None
+ def status(self, msg: str) -> None:
# for debugging
indicator = '-' * self.pos + '^'
print("%s\n%s\n%s" % (msg, self.definition, indicator))
- def fail(self, msg):
- # type: (str) -> None
+ def fail(self, msg: str) -> None:
errors = []
indicator = '-' * self.pos + '^'
exMain = DefinitionError(
@@ -4612,15 +4280,13 @@ class DefinitionParser:
self.otherErrors = []
raise self._make_multi_error(errors, '')
- def warn(self, msg):
- # type: (str) -> None
+ def warn(self, msg: str) -> None:
if self.warnEnv:
self.warnEnv.warn(msg)
else:
print("Warning: %s" % msg)
- def match(self, regex):
- # type: (Pattern) -> bool
+ def match(self, regex: Pattern) -> bool:
match = regex.match(self.definition, self.pos)
if match is not None:
self._previous_state = (self.pos, self.last_match)
@@ -4629,69 +4295,58 @@ class DefinitionParser:
return True
return False
- def backout(self):
- # type: () -> None
+ def backout(self) -> None:
self.pos, self.last_match = self._previous_state
- def skip_string(self, string):
- # type: (str) -> bool
+ def skip_string(self, string: str) -> bool:
strlen = len(string)
if self.definition[self.pos:self.pos + strlen] == string:
self.pos += strlen
return True
return False
- def skip_word(self, word):
- # type: (str) -> bool
+ def skip_word(self, word: str) -> bool:
return self.match(re.compile(r'\b%s\b' % re.escape(word)))
- def skip_ws(self):
- # type: () -> bool
+ def skip_ws(self) -> bool:
return self.match(_whitespace_re)
- def skip_word_and_ws(self, word):
- # type: (str) -> bool
+ def skip_word_and_ws(self, word: str) -> bool:
if self.skip_word(word):
self.skip_ws()
return True
return False
- def skip_string_and_ws(self, string):
- # type: (str) -> bool
+ def skip_string_and_ws(self, string: str) -> bool:
if self.skip_string(string):
self.skip_ws()
return True
return False
@property
- def eof(self):
- # type: () -> bool
+ def eof(self) -> bool:
return self.pos >= self.end
@property
- def current_char(self):
- # type: () -> str
+ def current_char(self) -> str:
try:
return self.definition[self.pos]
except IndexError:
return 'EOF'
@property
- def matched_text(self):
- # type: () -> str
+ def matched_text(self) -> str:
if self.last_match is not None:
return self.last_match.group()
else:
return None
- def read_rest(self):
- # type: () -> str
+ def read_rest(self) -> str:
rv = self.definition[self.pos:]
self.pos = self.end
return rv
- def assert_end(self):
- # type: () -> None
+ def assert_end(self) -> None:
self.skip_ws()
if not self.eof:
self.fail('Expected end of definition.')
@@ -4715,8 +4370,7 @@ class DefinitionParser:
self.pos += 1
return self.definition[startPos:self.pos]
- def _parse_balanced_token_seq(self, end):
- # type: (List[str]) -> str
+ def _parse_balanced_token_seq(self, end: List[str]) -> str:
# TODO: add handling of string literals and similar
brackets = {'(': ')', '[': ']', '{': '}'}
startPos = self.pos
@@ -4736,8 +4390,7 @@ class DefinitionParser:
% startPos)
return self.definition[startPos:self.pos]
- def _parse_attribute(self):
- # type: () -> Any
+ def _parse_attribute(self) -> Any:
self.skip_ws()
# try C++11 style
startPos = self.pos
@@ -4917,8 +4570,8 @@ class DefinitionParser:
return res
return self._parse_nested_name()
- def _parse_initializer_list(self, name, open, close):
- # type: (str, str, str) -> Tuple[List[Any], bool]
+ def _parse_initializer_list(self, name: str, open: str, close: str
+ ) -> Tuple[List[Any], bool]:
# Parse open and close with the actual initializer-list inbetween
# -> initializer-clause '...'[opt]
# | initializer-list ',' initializer-clause '...'[opt]
@@ -4949,8 +4602,7 @@ class DefinitionParser:
break
return exprs, trailingComma
- def _parse_paren_expression_list(self):
- # type: () -> ASTParenExprList
+ def _parse_paren_expression_list(self) -> ASTParenExprList:
# -> '(' expression-list ')'
# though, we relax it to also allow empty parens
# as it's needed in some cases
@@ -4963,8 +4615,7 @@ class DefinitionParser:
return None
return ASTParenExprList(exprs)
- def _parse_braced_init_list(self):
- # type: () -> ASTBracedInitList
+ def _parse_braced_init_list(self) -> ASTBracedInitList:
# -> '{' initializer-list ','[opt] '}'
# | '{' '}'
exprs, trailingComma = self._parse_initializer_list("braced-init-list", '{', '}')
@@ -4972,8 +4623,9 @@ class DefinitionParser:
return None
return ASTBracedInitList(exprs, trailingComma)
- def _parse_expression_list_or_braced_init_list(self):
- # type: () -> Union[ASTParenExprList, ASTBracedInitList]
+ def _parse_expression_list_or_braced_init_list(
+ self
+ ) -> Union[ASTParenExprList, ASTBracedInitList]:
paren = self._parse_paren_expression_list()
if paren is not None:
return paren
@@ -5382,8 +5034,7 @@ class DefinitionParser:
value = self.definition[startPos:self.pos].strip()
return ASTFallbackExpr(value.strip())
- def _parse_operator(self):
- # type: () -> ASTOperator
+ def _parse_operator(self) -> ASTOperator:
self.skip_ws()
# adapted from the old code
# thank god, a regular operator definition
@@ -5415,8 +5066,7 @@ class DefinitionParser:
type = self._parse_type(named=False, outer="operatorCast")
return ASTOperatorType(type)
- def _parse_template_argument_list(self):
- # type: () -> ASTTemplateArgs
+ def _parse_template_argument_list(self) -> ASTTemplateArgs:
self.skip_ws()
if not self.skip_string_and_ws('<'):
return None
@@ -5463,8 +5113,7 @@ class DefinitionParser:
break
return ASTTemplateArgs(templateArgs)
- def _parse_nested_name(self, memberPointer=False):
- # type: (bool) -> ASTNestedName
+ def _parse_nested_name(self, memberPointer: bool = False) -> ASTNestedName:
names = [] # type: List[Any]
templates = [] # type: List[bool]
@@ -5512,8 +5161,7 @@ class DefinitionParser:
break
return ASTNestedName(names, templates, rooted)
- def _parse_trailing_type_spec(self):
- # type: () -> Any
+ def _parse_trailing_type_spec(self) -> Any:
# fundemental types
self.skip_ws()
for t in self._simple_fundemental_types:
@@ -5568,8 +5216,7 @@ class DefinitionParser:
nestedName = self._parse_nested_name()
return ASTTrailingTypeSpecName(prefix, nestedName)
- def _parse_parameters_and_qualifiers(self, paramMode):
- # type: (str) -> ASTParametersQualifiers
+ def _parse_parameters_and_qualifiers(self, paramMode: str) -> ASTParametersQualifiers:
if paramMode == 'new':
return None
self.skip_ws()
@@ -5660,8 +5307,7 @@ class DefinitionParser:
args, volatile, const, refQual, exceptionSpec, override, final,
initializer)
- def _parse_decl_specs_simple(self, outer, typed):
- # type: (str, bool) -> ASTDeclSpecsSimple
+ def _parse_decl_specs_simple(self, outer: str, typed: bool) -> ASTDeclSpecsSimple:
"""Just parse the simple ones."""
storage = None
threadLocal = None
@@ -5735,8 +5381,7 @@ class DefinitionParser:
explicit, constexpr, volatile, const,
friend, attrs)
- def _parse_decl_specs(self, outer, typed=True):
- # type: (str, bool) -> ASTDeclSpecs
+ def _parse_decl_specs(self, outer: str, typed: bool = True) -> ASTDeclSpecs:
if outer:
if outer not in ('type', 'member', 'function', 'templateParam'):
raise Exception('Internal error, unknown outer "%s".' % outer)
@@ -5763,12 +5408,9 @@ class DefinitionParser:
trailing = None
return ASTDeclSpecs(outer, leftSpecs, rightSpecs, trailing)
- def _parse_declarator_name_suffix(self,
- named, # type: Union[bool, str]
- paramMode, # type: str
- typed # type: bool
- ):
- # type: (...) -> Union[ASTDeclaratorNameParamQual, ASTDeclaratorNameBitField]
+ def _parse_declarator_name_suffix(
+ self, named: Union[bool, str], paramMode: str, typed: bool
+ ) -> Union[ASTDeclaratorNameParamQual, ASTDeclaratorNameBitField]:
# now we should parse the name, and then suffixes
if named == 'maybe':
pos = self.pos
@@ -5821,8 +5463,8 @@ class DefinitionParser:
return ASTDeclaratorNameParamQual(declId=declId, arrayOps=arrayOps,
paramQual=paramQual)
- def _parse_declarator(self, named, paramMode, typed=True):
- # type: (Union[bool, str], str, bool) -> Any
+ def _parse_declarator(self, named: Union[bool, str], paramMode: str,
+ typed: bool = True) -> Any:
# 'typed' here means 'parse return type stuff'
if paramMode not in ('type', 'function', 'operatorCast', 'new'):
raise Exception(
@@ -5933,8 +5575,8 @@ class DefinitionParser:
header = "Error in declarator or parameters and qualifiers"
raise self._make_multi_error(prevErrors, header)
- def _parse_initializer(self, outer=None, allowFallback=True):
- # type: (str, bool) -> ASTInitializer
+ def _parse_initializer(self, outer: str = None, allowFallback: bool = True
+ ) -> ASTInitializer:
# initializer # global vars
# -> brace-or-equal-initializer
# | '(' expression-list ')'
@@ -5982,8 +5624,7 @@ class DefinitionParser:
value = self._parse_expression_fallback(fallbackEnd, parser, allow=allowFallback)
return ASTInitializer(value)
- def _parse_type(self, named, outer=None):
- # type: (Union[bool, str], str) -> ASTType
+ def _parse_type(self, named: Union[bool, str], outer: str = None) -> ASTType:
"""
named=False|'maybe'|True: 'maybe' is e.g., for function objects which
doesn't need to name the arguments
@@ -6065,8 +5706,7 @@ class DefinitionParser:
decl = self._parse_declarator(named=named, paramMode=paramMode)
return ASTType(declSpecs, decl)
- def _parse_type_with_init(self, named, outer):
- # type: (Union[bool, str], str) -> Any
+ def _parse_type_with_init(self, named: Union[bool, str], outer: str) -> Any:
if outer:
assert outer in ('type', 'member', 'function', 'templateParam')
type = self._parse_type(outer=outer, named=named)
@@ -6109,8 +5749,7 @@ class DefinitionParser:
msg += " or constrianted template paramter."
raise self._make_multi_error(errs, msg)
- def _parse_type_using(self):
- # type: () -> ASTTypeUsing
+ def _parse_type_using(self) -> ASTTypeUsing:
name = self._parse_nested_name()
self.skip_ws()
if not self.skip_string('='):
@@ -6118,15 +5757,13 @@ class DefinitionParser:
type = self._parse_type(False, None)
return ASTTypeUsing(name, type)
- def _parse_concept(self):
- # type: () -> ASTConcept
+ def _parse_concept(self) -> ASTConcept:
nestedName = self._parse_nested_name()
self.skip_ws()
initializer = self._parse_initializer('member')
return ASTConcept(nestedName, initializer)
- def _parse_class(self):
- # type: () -> ASTClass
+ def _parse_class(self) -> ASTClass:
name = self._parse_nested_name()
self.skip_ws()
final = self.skip_word_and_ws('final')
@@ -6156,13 +5793,11 @@ class DefinitionParser:
break
return ASTClass(name, final, bases)
- def _parse_union(self):
- # type: () -> ASTUnion
+ def _parse_union(self) -> ASTUnion:
name = self._parse_nested_name()
return ASTUnion(name)
- def _parse_enum(self):
- # type: () -> ASTEnum
+ def _parse_enum(self) -> ASTEnum:
scoped = None # is set by CPPEnumObject
self.skip_ws()
name = self._parse_nested_name()
@@ -6172,8 +5807,7 @@ class DefinitionParser:
underlyingType = self._parse_type(named=False)
return ASTEnum(name, scoped, underlyingType)
- def _parse_enumerator(self):
- # type: () -> ASTEnumerator
+ def _parse_enumerator(self) -> ASTEnumerator:
name = self._parse_nested_name()
self.skip_ws()
init = None
@@ -6186,8 +5820,7 @@ class DefinitionParser:
init = ASTInitializer(initVal)
return ASTEnumerator(name, init)
- def _parse_template_parameter_list(self):
- # type: () -> ASTTemplateParams
+ def _parse_template_parameter_list(self) -> "ASTTemplateParams":
# only: '<' parameter-list '>'
# we assume that 'template' has just been parsed
templateParams = [] # type: List
@@ -6258,8 +5891,7 @@ class DefinitionParser:
prevErrors.append((e, ""))
raise self._make_multi_error(prevErrors, header)
- def _parse_template_introduction(self):
- # type: () -> ASTTemplateIntroduction
+ def _parse_template_introduction(self) -> "ASTTemplateIntroduction":
pos = self.pos
try:
concept = self._parse_nested_name()
@@ -6297,8 +5929,8 @@ class DefinitionParser:
'Expected ",", or "}".')
return ASTTemplateIntroduction(concept, params)
- def _parse_template_declaration_prefix(self, objectType):
- # type: (str) -> ASTTemplateDeclarationPrefix
+ def _parse_template_declaration_prefix(self, objectType: str
+ ) -> ASTTemplateDeclarationPrefix:
templates = [] # type: List[str]
while 1:
self.skip_ws()
@@ -6327,13 +5959,10 @@ class DefinitionParser:
else:
return ASTTemplateDeclarationPrefix(templates)
- def _check_template_consistency(self,
- nestedName, # type: ASTNestedName
- templatePrefix, # type: ASTTemplateDeclarationPrefix
- fullSpecShorthand, # type: bool
- isMember=False # type: bool
- ):
- # type: (...) -> ASTTemplateDeclarationPrefix
+ def _check_template_consistency(self, nestedName: ASTNestedName,
+ templatePrefix: ASTTemplateDeclarationPrefix,
+ fullSpecShorthand: bool, isMember: bool = False
+ ) -> ASTTemplateDeclarationPrefix:
numArgs = nestedName.num_templates()
isMemberInstantiation = False
if not templatePrefix:
@@ -6369,8 +5998,7 @@ class DefinitionParser:
templatePrefix = ASTTemplateDeclarationPrefix(newTemplates)
return templatePrefix
- def parse_declaration(self, objectType, directiveType):
- # type: (str, str) -> ASTDeclaration
+ def parse_declaration(self, objectType: str, directiveType: str) -> ASTDeclaration:
if objectType not in ('class', 'union', 'function', 'member', 'type',
'concept', 'enum', 'enumerator'):
raise Exception('Internal error, unknown objectType "%s".' % objectType)
@@ -6430,8 +6058,7 @@ class DefinitionParser:
return ASTDeclaration(objectType, directiveType, visibility,
templatePrefix, declaration)
- def parse_namespace_object(self):
- # type: () -> ASTNamespace
+ def parse_namespace_object(self) -> ASTNamespace:
templatePrefix = self._parse_template_declaration_prefix(objectType="namespace")
name = self._parse_nested_name()
templatePrefix = self._check_template_consistency(name, templatePrefix,
@@ -6440,8 +6067,7 @@ class DefinitionParser:
res.objectType = 'namespace' # type: ignore
return res
- def parse_xref_object(self):
- # type: () -> Tuple[Any, bool]
+ def parse_xref_object(self) -> Tuple[Any, bool]:
pos = self.pos
try:
templatePrefix = self._parse_template_declaration_prefix(objectType="xref")
@@ -6492,8 +6118,7 @@ class DefinitionParser:
return expr
-def _make_phony_error_name():
- # type: () -> ASTNestedName
+def _make_phony_error_name() -> ASTNestedName:
nne = ASTNestedNameElement(ASTIdentifier("PhonyNameDueToError"), None)
return ASTNestedName([nne], [False], rooted=False)
@@ -6518,12 +6143,10 @@ class CPPObject(ObjectDescription):
option_spec = dict(ObjectDescription.option_spec)
option_spec['tparam-line-spec'] = directives.flag
- def warn(self, msg):
- # type: (Union[str, Exception]) -> None
+ def warn(self, msg: Union[str, Exception]) -> None:
self.state_machine.reporter.warning(msg, line=self.lineno)
- def _add_enumerator_to_parent(self, ast):
- # type: (ASTDeclaration) -> None
+ def _add_enumerator_to_parent(self, ast: ASTDeclaration) -> None:
assert ast.objectType == 'enumerator'
# find the parent, if it exists && is an enum
# && it's unscoped,
@@ -6564,8 +6187,8 @@ class CPPObject(ObjectDescription):
declaration=declClone,
docname=self.env.docname)
- def add_target_and_index(self, ast, sig, signode):
- # type: (ASTDeclaration, str, addnodes.desc_signature) -> None
+ def add_target_and_index(self, ast: ASTDeclaration, sig: str, signode: desc_signature
+ ) -> None:
# general note: name must be lstrip(':')'ed, to remove "::"
ids = []
for i in range(1, _max_id + 1):
@@ -6625,25 +6248,20 @@ class CPPObject(ObjectDescription):
self.state.document.note_explicit_target(signode)
@property
- def object_type(self):
- # type: () -> str
+ def object_type(self) -> str:
raise NotImplementedError()
@property
- def display_object_type(self):
- # type: () -> str
+ def display_object_type(self) -> str:
return self.object_type
- def get_index_text(self, name):
- # type: (str) -> str
+ def get_index_text(self, name: str) -> str:
return _('%s (C++ %s)') % (name, self.display_object_type)
- def parse_definition(self, parser):
- # type: (DefinitionParser) -> ASTDeclaration
+ def parse_definition(self, parser: DefinitionParser) -> ASTDeclaration:
return parser.parse_declaration(self.object_type, self.objtype)
- def describe_signature(self, signode, ast, options):
- # type: (addnodes.desc_signature, Any, Dict) -> None
+ def describe_signature(self, signode: desc_signature, ast: Any, options: Dict) -> None:
ast.describe_signature(signode, 'lastIsName', self.env, options)
def run(self):
@@ -6675,8 +6293,7 @@ class CPPObject(ObjectDescription):
return []
return super().run()
- def handle_signature(self, sig, signode):
- # type: (str, addnodes.desc_signature) -> ASTDeclaration
+ def handle_signature(self, sig: str, signode: desc_signature) -> ASTDeclaration:
parentSymbol = self.env.temp_data['cpp:parent_symbol']
parser = DefinitionParser(sig, self, self.env.config)
@@ -6711,8 +6328,7 @@ class CPPObject(ObjectDescription):
self.describe_signature(signode, ast, options)
return ast
- def before_content(self):
- # type: () -> None
+ def before_content(self) -> None:
lastSymbol = self.env.temp_data['cpp:last_symbol']
assert lastSymbol
self.oldParentSymbol = self.env.temp_data['cpp:parent_symbol']
@@ -6720,8 +6336,7 @@ class CPPObject(ObjectDescription):
self.env.temp_data['cpp:parent_symbol'] = lastSymbol
self.env.ref_context['cpp:parent_key'] = lastSymbol.get_lookup_key()
- def after_content(self):
- # type: () -> None
+ def after_content(self) -> None:
self.env.temp_data['cpp:parent_symbol'] = self.oldParentSymbol
self.env.ref_context['cpp:parent_key'] = self.oldParentKey
@@ -6776,12 +6391,10 @@ class CPPNamespaceObject(SphinxDirective):
final_argument_whitespace = True
option_spec = {} # type: Dict
- def warn(self, msg):
- # type: (Union[str, Exception]) -> None
+ def warn(self, msg: Union[str, Exception]) -> None:
self.state_machine.reporter.warning(msg, line=self.lineno)
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
rootSymbol = self.env.domaindata['cpp']['root_symbol']
if self.arguments[0].strip() in ('NULL', '0', 'nullptr'):
symbol = rootSymbol
@@ -6810,12 +6423,10 @@ class CPPNamespacePushObject(SphinxDirective):
final_argument_whitespace = True
option_spec = {} # type: Dict
- def warn(self, msg):
- # type: (Union[str, Exception]) -> None
+ def warn(self, msg: Union[str, Exception]) -> None:
self.state_machine.reporter.warning(msg, line=self.lineno)
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
if self.arguments[0].strip() in ('NULL', '0', 'nullptr'):
return []
parser = DefinitionParser(self.arguments[0], self, self.config)
@@ -6845,12 +6456,10 @@ class CPPNamespacePopObject(SphinxDirective):
final_argument_whitespace = True
option_spec = {} # type: Dict
- def warn(self, msg):
- # type: (Union[str, Exception]) -> None
+ def warn(self, msg: Union[str, Exception]) -> None:
self.state_machine.reporter.warning(msg, line=self.lineno)
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
stack = self.env.temp_data.get('cpp:namespace_stack', None)
if not stack or len(stack) == 0:
self.warn("C++ namespace pop on empty stack. Defaulting to gobal scope.")
@@ -6887,8 +6496,7 @@ class AliasNode(nodes.Element):
class AliasTransform(SphinxTransform):
default_priority = ReferencesResolver.default_priority - 1
- def apply(self, **kwargs):
- # type: (Any) -> None
+ def apply(self, **kwargs: Any) -> None:
for node in self.document.traverse(AliasNode):
class Warner:
def warn(self, msg):
@@ -6970,8 +6578,7 @@ class AliasTransform(SphinxTransform):
class CPPAliasObject(ObjectDescription):
option_spec = {} # type: Dict
- def run(self):
- # type: () -> List[nodes.Node]
+ def run(self) -> List[Node]:
"""
On purpose this doesn't call the ObjectDescription version, but is based on it.
Each alias signature may expand into multiple real signatures (an overload set).
@@ -7004,8 +6611,8 @@ class CPPAliasObject(ObjectDescription):
class CPPXRefRole(XRefRole):
- def process_link(self, env, refnode, has_explicit_title, title, target):
- # type: (BuildEnvironment, nodes.Element, bool, str, str) -> Tuple[str, str]
+ def process_link(self, env: BuildEnvironment, refnode: Element, has_explicit_title: bool,
+ title: str, target: str) -> Tuple[str, str]:
refnode.attributes.update(env.ref_context)
if not has_explicit_title:
@@ -7135,8 +6742,7 @@ class CPPDomain(Domain):
'names': {} # full name for indexing -> docname
}
- def clear_doc(self, docname):
- # type: (str) -> None
+ def clear_doc(self, docname: str) -> None:
if Symbol.debug_show_tree:
print("clear_doc:", docname)
print("\tbefore:")
@@ -7155,19 +6761,17 @@ class CPPDomain(Domain):
if nDocname == docname:
del self.data['names'][name]
- def process_doc(self, env, docname, document):
- # type: (BuildEnvironment, str, nodes.document) -> None
+ def process_doc(self, env: BuildEnvironment, docname: str,
+ document: nodes.document) -> None:
if Symbol.debug_show_tree:
print("process_doc:", docname)
print(self.data['root_symbol'].dump(0))
print("process_doc end:", docname)
- def process_field_xref(self, pnode):
- # type: (addnodes.pending_xref) -> None
+ def process_field_xref(self, pnode: pending_xref) -> None:
pnode.attributes.update(self.env.ref_context)
- def merge_domaindata(self, docnames, otherdata):
- # type: (List[str], Dict) -> None
+ def merge_domaindata(self, docnames: List[str], otherdata: Dict) -> None:
if Symbol.debug_show_tree:
print("merge_domaindata:")
print("\tself:")
@@ -7191,9 +6795,9 @@ class CPPDomain(Domain):
else:
ourNames[name] = docname
- def _resolve_xref_inner(self, env, fromdocname, builder, typ,
- target, node, contnode, emitWarnings=True):
- # type: (BuildEnvironment, str, Builder, str, str, addnodes.pending_xref, nodes.Element, bool) -> Tuple[nodes.Element, str] # NOQA
+ def _resolve_xref_inner(self, env: BuildEnvironment, fromdocname: str, builder: Builder,
+ typ: str, target: str, node: pending_xref, contnode: Element,
+ emitWarnings: bool = True) -> Tuple[Element, str]:
class Warner:
def warn(self, msg):
if emitWarnings:
@@ -7329,13 +6933,15 @@ class CPPDomain(Domain):
declaration.get_newest_id(), contnode, displayName
), declaration.objectType
- def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode):
- # type: (BuildEnvironment, str, Builder, str, str, addnodes.pending_xref, nodes.Element) -> nodes.Element # NOQA
+ def resolve_xref(self, env: BuildEnvironment, fromdocname: str, builder: Builder,
+ typ: str, target: str, node: pending_xref, contnode: Element
+ ) -> Element:
return self._resolve_xref_inner(env, fromdocname, builder, typ,
target, node, contnode)[0]
- def resolve_any_xref(self, env, fromdocname, builder, target, node, contnode):
- # type: (BuildEnvironment, str, Builder, str, addnodes.pending_xref, nodes.Element) -> List[Tuple[str, nodes.Element]] # NOQA
+ def resolve_any_xref(self, env: BuildEnvironment, fromdocname: str, builder: Builder,
+ target: str, node: pending_xref, contnode: Element
+ ) -> List[Tuple[str, Element]]:
retnode, objtype = self._resolve_xref_inner(env, fromdocname, builder,
'any', target, node, contnode,
emitWarnings=False)
@@ -7346,8 +6952,7 @@ class CPPDomain(Domain):
return [('cpp:' + self.role_for_objtype(objtype), retnode)]
return []
- def get_objects(self):
- # type: () -> Iterator[Tuple[str, str, str, str, str, int]]
+ def get_objects(self) -> Iterator[Tuple[str, str, str, str, str, int]]:
rootSymbol = self.data['root_symbol']
for symbol in rootSymbol.get_all_symbols():
if symbol.declaration is None:
@@ -7361,8 +6966,7 @@ class CPPDomain(Domain):
newestId = symbol.declaration.get_newest_id()
yield (name, dispname, objectType, docname, newestId, 1)
- def get_full_qualified_name(self, node):
- # type: (nodes.Element) -> str
+ def get_full_qualified_name(self, node: Element) -> str:
target = node.get('reftarget', None)
if target is None:
return None
@@ -7376,8 +6980,7 @@ class CPPDomain(Domain):
return '::'.join([str(parentName), target])
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: Sphinx) -> Dict[str, Any]:
app.add_domain(CPPDomain)
app.add_config_value("cpp_index_common_prefix", [], 'env')
app.add_config_value("cpp_id_attributes", [], 'env')
diff --git a/sphinx/domains/index.py b/sphinx/domains/index.py
index 4b1fd2bb6..d0bdbcfe0 100644
--- a/sphinx/domains/index.py
+++ b/sphinx/domains/index.py
@@ -4,20 +4,26 @@
The index domain.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from typing import Any, Dict, Iterable, List, Tuple
-from docutils.nodes import Node
+from docutils import nodes
+from docutils.nodes import Node, system_message
from sphinx import addnodes
-from sphinx.application import Sphinx
from sphinx.domains import Domain
from sphinx.environment import BuildEnvironment
from sphinx.util import logging
from sphinx.util import split_index_msg
+from sphinx.util.docutils import ReferenceRole, SphinxDirective
+from sphinx.util.nodes import process_index_entry
+
+if False:
+ # For type annotation
+ from sphinx.application import Sphinx
logger = logging.getLogger(__name__)
@@ -54,8 +60,57 @@ class IndexDomain(Domain):
entries.append(entry)
-def setup(app: Sphinx) -> Dict[str, Any]:
+class IndexDirective(SphinxDirective):
+ """
+ Directive to add entries to the index.
+ """
+ has_content = False
+ required_arguments = 1
+ optional_arguments = 0
+ final_argument_whitespace = True
+ option_spec = {} # type: Dict
+
+ def run(self) -> List[Node]:
+ arguments = self.arguments[0].split('\n')
+ targetid = 'index-%s' % self.env.new_serialno('index')
+ targetnode = nodes.target('', '', ids=[targetid])
+ self.state.document.note_explicit_target(targetnode)
+ indexnode = addnodes.index()
+ indexnode['entries'] = []
+ indexnode['inline'] = False
+ self.set_source_info(indexnode)
+ for entry in arguments:
+ indexnode['entries'].extend(process_index_entry(entry, targetid))
+ return [indexnode, targetnode]
+
+
+class IndexRole(ReferenceRole):
+ def run(self) -> Tuple[List[Node], List[system_message]]:
+ target_id = 'index-%s' % self.env.new_serialno('index')
+ if self.has_explicit_title:
+ # if an explicit target is given, process it as a full entry
+ title = self.title
+ entries = process_index_entry(self.target, target_id)
+ else:
+ # otherwise we just create a single entry
+ if self.target.startswith('!'):
+ title = self.title[1:]
+ entries = [('single', self.target[1:], target_id, 'main', None)]
+ else:
+ title = self.title
+ entries = [('single', self.target, target_id, '', None)]
+
+ index = addnodes.index(entries=entries)
+ target = nodes.target('', '', ids=[target_id])
+ text = nodes.Text(title, title)
+ self.set_source_info(index)
+ return [index, target, text], []
+
+
+def setup(app: "Sphinx") -> Dict[str, Any]:
app.add_domain(IndexDomain)
+ app.add_directive('index', IndexDirective)
+ app.add_role('index', IndexRole())
return {
'version': 'builtin',
diff --git a/sphinx/domains/javascript.py b/sphinx/domains/javascript.py
index da695065b..feb39bc9d 100644
--- a/sphinx/domains/javascript.py
+++ b/sphinx/domains/javascript.py
@@ -4,7 +4,7 @@
The JavaScript domain.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/domains/math.py b/sphinx/domains/math.py
index 21a3fac76..88b6e4eb8 100644
--- a/sphinx/domains/math.py
+++ b/sphinx/domains/math.py
@@ -4,7 +4,7 @@
The math domain.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py
index 3e11173dc..f23c50256 100644
--- a/sphinx/domains/python.py
+++ b/sphinx/domains/python.py
@@ -4,7 +4,7 @@
The Python domain.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/domains/rst.py b/sphinx/domains/rst.py
index 85f10e15c..81287c815 100644
--- a/sphinx/domains/rst.py
+++ b/sphinx/domains/rst.py
@@ -4,7 +4,7 @@
The reStructuredText domain.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py
index dc35b1c2b..eafec90e1 100644
--- a/sphinx/domains/std.py
+++ b/sphinx/domains/std.py
@@ -4,7 +4,7 @@
The standard domain.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -643,7 +643,7 @@ class StandardDomain(Domain):
self.progoptions[program, name] = (docname, labelid)
def build_reference_node(self, fromdocname: str, builder: "Builder", docname: str,
- labelid: str, sectname: str, rolename: str, **options
+ labelid: str, sectname: str, rolename: str, **options: Any
) -> Element:
nodeclass = options.pop('nodeclass', nodes.reference)
newnode = nodeclass('', '', internal=True, **options)
diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py
index aa2bfed99..341f22a27 100644
--- a/sphinx/environment/__init__.py
+++ b/sphinx/environment/__init__.py
@@ -4,7 +4,7 @@
Global creation environment.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/environment/adapters/__init__.py b/sphinx/environment/adapters/__init__.py
index 45bedefe8..c9cde6364 100644
--- a/sphinx/environment/adapters/__init__.py
+++ b/sphinx/environment/adapters/__init__.py
@@ -4,6 +4,6 @@
Sphinx environment adapters
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/environment/adapters/asset.py b/sphinx/environment/adapters/asset.py
index bc282de0c..38e4eb064 100644
--- a/sphinx/environment/adapters/asset.py
+++ b/sphinx/environment/adapters/asset.py
@@ -4,7 +4,7 @@
Assets adapter for sphinx.environment.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/environment/adapters/indexentries.py b/sphinx/environment/adapters/indexentries.py
index 9394f92bc..1d135bd32 100644
--- a/sphinx/environment/adapters/indexentries.py
+++ b/sphinx/environment/adapters/indexentries.py
@@ -4,7 +4,7 @@
Index entries adapters for sphinx.environment.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import bisect
diff --git a/sphinx/environment/adapters/toctree.py b/sphinx/environment/adapters/toctree.py
index 0975b33cd..fe8f43656 100644
--- a/sphinx/environment/adapters/toctree.py
+++ b/sphinx/environment/adapters/toctree.py
@@ -4,12 +4,12 @@
Toctree adapter for sphinx.environment.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
+from typing import Any, Iterable, List
from typing import cast
-from typing import Iterable, List
from docutils import nodes
from docutils.nodes import Element, Node
@@ -314,8 +314,8 @@ class TocTree:
node['refuri'] = node['anchorname'] or '#'
return toc
- def get_toctree_for(self, docname: str, builder: "Builder", collapse: bool, **kwds
- ) -> Element:
+ def get_toctree_for(self, docname: str, builder: "Builder", collapse: bool,
+ **kwds: Any) -> Element:
"""Return the global TOC nodetree."""
doctree = self.env.get_doctree(self.env.config.master_doc)
toctrees = [] # type: List[Element]
diff --git a/sphinx/environment/collectors/__init__.py b/sphinx/environment/collectors/__init__.py
index 137a10302..53e3a1c72 100644
--- a/sphinx/environment/collectors/__init__.py
+++ b/sphinx/environment/collectors/__init__.py
@@ -4,7 +4,7 @@
The data collector components for sphinx.environment.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/environment/collectors/asset.py b/sphinx/environment/collectors/asset.py
index e1d3abef1..06a0d5198 100644
--- a/sphinx/environment/collectors/asset.py
+++ b/sphinx/environment/collectors/asset.py
@@ -4,7 +4,7 @@
The image collector for sphinx.environment.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/environment/collectors/dependencies.py b/sphinx/environment/collectors/dependencies.py
index 63ae63e84..cc0af037e 100644
--- a/sphinx/environment/collectors/dependencies.py
+++ b/sphinx/environment/collectors/dependencies.py
@@ -4,7 +4,7 @@
The dependencies collector components for sphinx.environment.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/environment/collectors/indexentries.py b/sphinx/environment/collectors/indexentries.py
index 640eb915b..2ef59909b 100644
--- a/sphinx/environment/collectors/indexentries.py
+++ b/sphinx/environment/collectors/indexentries.py
@@ -4,7 +4,7 @@
Index entries collector for sphinx.environment.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/environment/collectors/metadata.py b/sphinx/environment/collectors/metadata.py
index a547d2551..bcff1f273 100644
--- a/sphinx/environment/collectors/metadata.py
+++ b/sphinx/environment/collectors/metadata.py
@@ -4,7 +4,7 @@
The metadata collector components for sphinx.environment.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/environment/collectors/title.py b/sphinx/environment/collectors/title.py
index 7d464f874..10cd6c5b0 100644
--- a/sphinx/environment/collectors/title.py
+++ b/sphinx/environment/collectors/title.py
@@ -4,7 +4,7 @@
The title collector components for sphinx.environment.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/environment/collectors/toctree.py b/sphinx/environment/collectors/toctree.py
index bacfc4baa..e168bd9c4 100644
--- a/sphinx/environment/collectors/toctree.py
+++ b/sphinx/environment/collectors/toctree.py
@@ -4,7 +4,7 @@
Toctree collector for sphinx.environment.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/errors.py b/sphinx/errors.py
index d67d6d1f7..a9d027cb8 100644
--- a/sphinx/errors.py
+++ b/sphinx/errors.py
@@ -5,7 +5,7 @@
Contains SphinxError and a few subclasses (in an extra module to avoid
circular import problems).
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/events.py b/sphinx/events.py
index 52a87439b..e6ea379eb 100644
--- a/sphinx/events.py
+++ b/sphinx/events.py
@@ -6,7 +6,7 @@
Gracefully adapted from the TextPress system by Armin.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -81,7 +81,7 @@ class EventManager:
for event in self.listeners.values():
event.pop(listener_id, None)
- def emit(self, name: str, *args) -> List:
+ def emit(self, name: str, *args: Any) -> List:
"""Emit a Sphinx event."""
try:
logger.debug('[app] emitting event: %r%s', name, repr(args)[:100])
@@ -99,7 +99,7 @@ class EventManager:
results.append(callback(self.app, *args))
return results
- def emit_firstresult(self, name: str, *args) -> Any:
+ def emit_firstresult(self, name: str, *args: Any) -> Any:
"""Emit a Sphinx event and returns first result.
This returns the result of the first handler that doesn't return ``None``.
diff --git a/sphinx/ext/__init__.py b/sphinx/ext/__init__.py
index 729148a03..4f4fd0127 100644
--- a/sphinx/ext/__init__.py
+++ b/sphinx/ext/__init__.py
@@ -4,6 +4,6 @@
Contains Sphinx features not activated by default.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/apidoc.py b/sphinx/ext/apidoc.py
index 16eea9c11..42605aeae 100644
--- a/sphinx/ext/apidoc.py
+++ b/sphinx/ext/apidoc.py
@@ -10,7 +10,7 @@
Copyright 2008 Société des arts technologiques (SAT),
https://sat.qc.ca/
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py
index 39c68a3cc..ea6a235c9 100644
--- a/sphinx/ext/autodoc/__init__.py
+++ b/sphinx/ext/autodoc/__init__.py
@@ -6,7 +6,7 @@
the doctree, thus avoiding duplication between docstrings and documentation
for those who like elaborate docstrings.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -227,7 +227,7 @@ class Documenter:
option_spec = {'noindex': bool_option} # type: Dict[str, Callable]
- def get_attr(self, obj: Any, name: str, *defargs) -> Any:
+ def get_attr(self, obj: Any, name: str, *defargs: Any) -> Any:
"""getattr() override for types such as Zope interfaces."""
return autodoc_attrgetter(self.env.app, obj, name, *defargs)
@@ -357,7 +357,7 @@ class Documenter:
return False
return True
- def format_args(self, **kwargs) -> str:
+ def format_args(self, **kwargs: Any) -> str:
"""Format the argument signature of *self.object*.
Should return None if the object does not have a signature.
@@ -375,7 +375,7 @@ class Documenter:
# directives of course)
return '.'.join(self.objpath) or self.modname
- def format_signature(self, **kwargs) -> str:
+ def format_signature(self, **kwargs: Any) -> str:
"""Format the signature (arguments and return annotation) of the object.
Let the user process it via the ``autodoc-process-signature`` event.
@@ -773,7 +773,7 @@ class ModuleDocumenter(Documenter):
'imported-members': bool_option, 'ignore-module-all': bool_option
} # type: Dict[str, Callable]
- def __init__(self, *args) -> None:
+ def __init__(self, *args: Any) -> None:
super().__init__(*args)
merge_special_members_option(self.options)
@@ -951,7 +951,7 @@ class DocstringSignatureMixin:
return lines
return super().get_doc(None, ignore) # type: ignore
- def format_signature(self, **kwargs) -> str:
+ def format_signature(self, **kwargs: Any) -> str:
if self.args is None and self.env.config.autodoc_docstring_signature: # type: ignore
# only act if a signature is not explicitly given already, and if
# the feature is enabled
@@ -966,7 +966,7 @@ class DocstringStripSignatureMixin(DocstringSignatureMixin):
Mixin for AttributeDocumenter to provide the
feature of stripping any function signature from the docstring.
"""
- def format_signature(self, **kwargs) -> str:
+ def format_signature(self, **kwargs: Any) -> str:
if self.args is None and self.env.config.autodoc_docstring_signature: # type: ignore
# only act if a signature is not explicitly given already, and if
# the feature is enabled
@@ -993,7 +993,7 @@ class FunctionDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # typ
return (inspect.isfunction(member) or inspect.isbuiltin(member) or
(inspect.isroutine(member) and isinstance(parent, ModuleDocumenter)))
- def format_args(self, **kwargs) -> str:
+ def format_args(self, **kwargs: Any) -> str:
if self.env.config.autodoc_typehints == 'none':
kwargs.setdefault('show_annotation', False)
@@ -1070,7 +1070,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type:
'private-members': bool_option, 'special-members': members_option,
} # type: Dict[str, Callable]
- def __init__(self, *args) -> None:
+ def __init__(self, *args: Any) -> None:
super().__init__(*args)
merge_special_members_option(self.options)
@@ -1090,7 +1090,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type:
self.doc_as_attr = True
return ret
- def format_args(self, **kwargs) -> str:
+ def format_args(self, **kwargs: Any) -> str:
if self.env.config.autodoc_typehints == 'none':
kwargs.setdefault('show_annotation', False)
@@ -1110,7 +1110,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type:
# with __init__ in C
return None
- def format_signature(self, **kwargs) -> str:
+ def format_signature(self, **kwargs: Any) -> str:
if self.doc_as_attr:
return ''
@@ -1298,7 +1298,7 @@ class MethodDocumenter(DocstringSignatureMixin, ClassLevelDocumenter): # type:
return ret
- def format_args(self, **kwargs) -> str:
+ def format_args(self, **kwargs: Any) -> str:
if self.env.config.autodoc_typehints == 'none':
kwargs.setdefault('show_annotation', False)
@@ -1313,7 +1313,7 @@ class MethodDocumenter(DocstringSignatureMixin, ClassLevelDocumenter): # type:
args = args.replace('\\', '\\\\')
return args
- def add_directive_header(self, sig) -> None:
+ def add_directive_header(self, sig: str) -> None:
super().add_directive_header(sig)
sourcename = self.get_sourcename()
@@ -1515,7 +1515,7 @@ def get_documenters(app: Sphinx) -> Dict[str, "Type[Documenter]"]:
return app.registry.documenters
-def autodoc_attrgetter(app: Sphinx, obj: Any, name: str, *defargs) -> Any:
+def autodoc_attrgetter(app: Sphinx, obj: Any, name: str, *defargs: Any) -> Any:
"""Alternative getattr() for types"""
for typ, func in app.registry.autodoc_attrgettrs.items():
if isinstance(obj, typ):
diff --git a/sphinx/ext/autodoc/importer.py b/sphinx/ext/autodoc/importer.py
index 3c617f223..cf0e3ea35 100644
--- a/sphinx/ext/autodoc/importer.py
+++ b/sphinx/ext/autodoc/importer.py
@@ -4,7 +4,7 @@
Importer utilities for autodoc
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/autodoc/mock.py b/sphinx/ext/autodoc/mock.py
index bc57d9078..169034664 100644
--- a/sphinx/ext/autodoc/mock.py
+++ b/sphinx/ext/autodoc/mock.py
@@ -4,7 +4,7 @@
mock for autodoc
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -26,7 +26,7 @@ class _MockObject:
__display_name__ = '_MockObject'
- def __new__(cls, *args, **kwargs) -> Any:
+ def __new__(cls, *args: Any, **kwargs: Any) -> Any:
if len(args) == 3 and isinstance(args[1], tuple):
superclass = args[1][-1].__class__
if superclass is cls:
@@ -36,7 +36,7 @@ class _MockObject:
return super().__new__(cls)
- def __init__(self, *args, **kwargs) -> None:
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
self.__qualname__ = ''
def __len__(self) -> int:
@@ -57,7 +57,7 @@ class _MockObject:
def __getattr__(self, key: str) -> "_MockObject":
return _make_subclass(key, self.__display_name__, self.__class__)()
- def __call__(self, *args, **kw) -> Any:
+ def __call__(self, *args: Any, **kw: Any) -> Any:
if args and type(args[0]) in [type, FunctionType, MethodType]:
# Appears to be a decorator, pass through unchanged
return args[0]
diff --git a/sphinx/ext/autosectionlabel.py b/sphinx/ext/autosectionlabel.py
index 9173fecf0..9890cdf7d 100644
--- a/sphinx/ext/autosectionlabel.py
+++ b/sphinx/ext/autosectionlabel.py
@@ -4,7 +4,7 @@
Allow reference sections by :ref: role using its title.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py
index 7d92fa06a..3d296cbde 100644
--- a/sphinx/ext/autosummary/__init__.py
+++ b/sphinx/ext/autosummary/__init__.py
@@ -48,7 +48,7 @@
resolved to a Python object, and otherwise it becomes simple emphasis.
This can be used as the default role to make links 'smart'.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py
index d72c12529..b42d80544 100644
--- a/sphinx/ext/autosummary/generate.py
+++ b/sphinx/ext/autosummary/generate.py
@@ -13,7 +13,7 @@
generate:
sphinx-autogen -o source/generated source/*.rst
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -62,7 +62,7 @@ class DummyApplication:
self._warncount = 0
self.warningiserror = False
- def emit_firstresult(self, *args) -> None:
+ def emit_firstresult(self, *args: Any) -> None:
pass
diff --git a/sphinx/ext/coverage.py b/sphinx/ext/coverage.py
index 7d53e7bb9..987cf2919 100644
--- a/sphinx/ext/coverage.py
+++ b/sphinx/ext/coverage.py
@@ -5,7 +5,7 @@
Check Python modules and C API for coverage. Mostly written by Josip
Dzolonga for the Google Highly Open Participation contest.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -80,7 +80,7 @@ class CoverageBuilder(Builder):
def get_outdated_docs(self) -> str:
return 'coverage overview'
- def write(self, *ignored) -> None:
+ def write(self, *ignored: Any) -> None:
self.py_undoc = {} # type: Dict[str, Dict[str, Any]]
self.build_py_coverage()
self.write_py_coverage()
diff --git a/sphinx/ext/doctest.py b/sphinx/ext/doctest.py
index 1c356ff6d..645521f9b 100644
--- a/sphinx/ext/doctest.py
+++ b/sphinx/ext/doctest.py
@@ -5,7 +5,7 @@
Mimic doctest by automatically executing code snippets and checking
their results.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/duration.py b/sphinx/ext/duration.py
index 1286e49ec..02e60cf7e 100644
--- a/sphinx/ext/duration.py
+++ b/sphinx/ext/duration.py
@@ -4,7 +4,7 @@
Measure durations of Sphinx processing.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -32,7 +32,7 @@ class DurationDomain(Domain):
def reading_durations(self) -> Dict[str, timedelta]:
return self.data.setdefault('reading_durations', {})
- def note_reading_duration(self, duration: timedelta):
+ def note_reading_duration(self, duration: timedelta) -> None:
self.reading_durations[self.env.docname] = duration
def clear(self) -> None:
@@ -69,7 +69,7 @@ def on_doctree_read(app: Sphinx, doctree: nodes.document) -> None:
domain.note_reading_duration(duration)
-def on_build_finished(app: Sphinx, error):
+def on_build_finished(app: Sphinx, error: Exception) -> None:
"""Display duration ranking on current build."""
domain = cast(DurationDomain, app.env.get_domain('duration'))
durations = sorted(domain.reading_durations.items(), key=itemgetter(1), reverse=True)
diff --git a/sphinx/ext/extlinks.py b/sphinx/ext/extlinks.py
index 39a989f23..ff3adb357 100644
--- a/sphinx/ext/extlinks.py
+++ b/sphinx/ext/extlinks.py
@@ -19,7 +19,7 @@
You can also give an explicit caption, e.g. :exmpl:`Foo <foo>`.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/githubpages.py b/sphinx/ext/githubpages.py
index 6a07c651a..4564ce60e 100644
--- a/sphinx/ext/githubpages.py
+++ b/sphinx/ext/githubpages.py
@@ -4,7 +4,7 @@
To publish HTML docs at GitHub Pages, create .nojekyll file.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/graphviz.py b/sphinx/ext/graphviz.py
index c16952bc0..27b64fbce 100644
--- a/sphinx/ext/graphviz.py
+++ b/sphinx/ext/graphviz.py
@@ -5,7 +5,7 @@
Allow graphviz-formatted graphs to be included in Sphinx-generated
documents inline.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -121,6 +121,7 @@ class Graphviz(SphinxDirective):
'layout': directives.unchanged,
'graphviz_dot': directives.unchanged, # an old alias of `layout` option
'name': directives.unchanged,
+ 'class': directives.class_option,
}
def run(self) -> List[Node]:
@@ -158,6 +159,8 @@ class Graphviz(SphinxDirective):
node['alt'] = self.options['alt']
if 'align' in self.options:
node['align'] = self.options['align']
+ if 'class' in self.options:
+ node['classes'] = self.options['class']
if 'caption' not in self.options:
self.add_name(node)
@@ -182,6 +185,7 @@ class GraphvizSimple(SphinxDirective):
'caption': directives.unchanged,
'graphviz_dot': directives.unchanged,
'name': directives.unchanged,
+ 'class': directives.class_option,
}
def run(self) -> List[Node]:
@@ -195,6 +199,8 @@ class GraphvizSimple(SphinxDirective):
node['alt'] = self.options['alt']
if 'align' in self.options:
node['align'] = self.options['align']
+ if 'class' in self.options:
+ node['classes'] = self.options['class']
if 'caption' not in self.options:
self.add_name(node)
@@ -267,10 +273,8 @@ def render_dot_html(self: HTMLTranslator, node: graphviz, code: str, options: Di
logger.warning(__('dot code %r: %s'), code, exc)
raise nodes.SkipNode
- if imgcls:
- imgcls += " graphviz"
- else:
- imgcls = "graphviz"
+ classes = [imgcls, 'graphviz'] + node.get('classes', [])
+ imgcls = ' '.join(filter(None, classes))
if fname is None:
self.body.append(self.encode(code))
diff --git a/sphinx/ext/ifconfig.py b/sphinx/ext/ifconfig.py
index a6d3f78e8..0e652509f 100644
--- a/sphinx/ext/ifconfig.py
+++ b/sphinx/ext/ifconfig.py
@@ -15,7 +15,7 @@
namespace of the project configuration (that is, all variables from
``conf.py`` are available.)
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/imgconverter.py b/sphinx/ext/imgconverter.py
index 3799cbe64..b95ef2588 100644
--- a/sphinx/ext/imgconverter.py
+++ b/sphinx/ext/imgconverter.py
@@ -4,7 +4,7 @@
Image converter extension for Sphinx
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/imgmath.py b/sphinx/ext/imgmath.py
index f49ecd9fa..4297ad182 100644
--- a/sphinx/ext/imgmath.py
+++ b/sphinx/ext/imgmath.py
@@ -4,7 +4,7 @@
Render math in HTML via dvipng or dvisvgm.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/inheritance_diagram.py b/sphinx/ext/inheritance_diagram.py
index fc7fadabd..83e277523 100644
--- a/sphinx/ext/inheritance_diagram.py
+++ b/sphinx/ext/inheritance_diagram.py
@@ -31,7 +31,7 @@ r"""
The graph is inserted as a PNG+image map into HTML and a PDF in
LaTeX.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/intersphinx.py b/sphinx/ext/intersphinx.py
index a403698f2..da0988b79 100644
--- a/sphinx/ext/intersphinx.py
+++ b/sphinx/ext/intersphinx.py
@@ -19,7 +19,7 @@
also be specified individually, e.g. if the docs should be buildable
without Internet access.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/jsmath.py b/sphinx/ext/jsmath.py
index 84f191a5e..75369a5ca 100644
--- a/sphinx/ext/jsmath.py
+++ b/sphinx/ext/jsmath.py
@@ -5,7 +5,7 @@
Set up everything for use of JSMath to display math in HTML
via JavaScript.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/linkcode.py b/sphinx/ext/linkcode.py
index e8635d926..68e8603f7 100644
--- a/sphinx/ext/linkcode.py
+++ b/sphinx/ext/linkcode.py
@@ -4,7 +4,7 @@
Add external links to module code in Python object descriptions.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/mathjax.py b/sphinx/ext/mathjax.py
index ebf2bc0e0..e13dcbeb7 100644
--- a/sphinx/ext/mathjax.py
+++ b/sphinx/ext/mathjax.py
@@ -6,7 +6,7 @@
Sphinx's HTML writer -- requires the MathJax JavaScript library on your
webserver/computer.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/napoleon/__init__.py b/sphinx/ext/napoleon/__init__.py
index d211a050e..10b1ff3a3 100644
--- a/sphinx/ext/napoleon/__init__.py
+++ b/sphinx/ext/napoleon/__init__.py
@@ -4,7 +4,7 @@
Support for NumPy and Google style docstrings.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -265,7 +265,7 @@ class Config:
'napoleon_custom_sections': (None, 'env')
}
- def __init__(self, **settings) -> None:
+ def __init__(self, **settings: Any) -> None:
for name, (default, rebuild) in self._config_values.items():
setattr(self, name, default)
for name, value in settings.items():
diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py
index bb77aa22d..a06a79cea 100644
--- a/sphinx/ext/napoleon/docstring.py
+++ b/sphinx/ext/napoleon/docstring.py
@@ -6,7 +6,7 @@
Classes for docstring parsing and formatting.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/napoleon/iterators.py b/sphinx/ext/napoleon/iterators.py
index 03b0474cb..e91a3ec14 100644
--- a/sphinx/ext/napoleon/iterators.py
+++ b/sphinx/ext/napoleon/iterators.py
@@ -6,7 +6,7 @@
A collection of helpful iterators.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -47,7 +47,7 @@ class peek_iter:
be set to a new object instance: ``object()``.
"""
- def __init__(self, *args) -> None:
+ def __init__(self, *args: Any) -> None:
"""__init__(o, sentinel=None)"""
self._iterable = iter(*args) # type: Iterable
self._cache = collections.deque() # type: collections.deque
@@ -206,7 +206,7 @@ class modify_iter(peek_iter):
"whitespace."
"""
- def __init__(self, *args, **kwargs) -> None:
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
"""__init__(o, sentinel=None, modifier=lambda x: x)"""
if 'modifier' in kwargs:
self.modifier = kwargs['modifier']
diff --git a/sphinx/ext/todo.py b/sphinx/ext/todo.py
index 99dc02d3d..69aaaf8b2 100644
--- a/sphinx/ext/todo.py
+++ b/sphinx/ext/todo.py
@@ -7,7 +7,7 @@
all todos of your project and lists them along with a backlink to the
original location.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/ext/viewcode.py b/sphinx/ext/viewcode.py
index 5bbec60a9..09fcd695f 100644
--- a/sphinx/ext/viewcode.py
+++ b/sphinx/ext/viewcode.py
@@ -4,7 +4,7 @@
Add links to module code in Python object descriptions.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/extension.py b/sphinx/extension.py
index 3cab20c2f..45ea46677 100644
--- a/sphinx/extension.py
+++ b/sphinx/extension.py
@@ -4,7 +4,7 @@
Utilities for Sphinx extensions.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -23,7 +23,7 @@ logger = logging.getLogger(__name__)
class Extension:
- def __init__(self, name: str, module: Any, **kwargs) -> None:
+ def __init__(self, name: str, module: Any, **kwargs: Any) -> None:
self.name = name
self.module = module
self.metadata = kwargs
diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py
index 9ef753253..f3445d1bd 100644
--- a/sphinx/highlighting.py
+++ b/sphinx/highlighting.py
@@ -4,7 +4,7 @@
Highlight code blocks using Pygments.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -84,7 +84,7 @@ class PygmentsBridge:
else:
return get_style_by_name(stylename)
- def get_formatter(self, **kwargs) -> Formatter:
+ def get_formatter(self, **kwargs: Any) -> Formatter:
kwargs.update(self.formatter_args)
return self.formatter(**kwargs)
@@ -133,7 +133,7 @@ class PygmentsBridge:
return lexer
def highlight_block(self, source: str, lang: str, opts: Dict = None,
- force: bool = False, location: Any = None, **kwargs) -> str:
+ force: bool = False, location: Any = None, **kwargs: Any) -> str:
if not isinstance(source, str):
source = source.decode()
diff --git a/sphinx/io.py b/sphinx/io.py
index 8f8eada4d..18b4f053e 100644
--- a/sphinx/io.py
+++ b/sphinx/io.py
@@ -4,7 +4,7 @@
Input/Output files
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import codecs
@@ -55,7 +55,7 @@ class SphinxBaseReader(standalone.Reader):
transforms = [] # type: List[Type[Transform]]
- def __init__(self, *args, **kwargs) -> None:
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
from sphinx.application import Sphinx
if len(args) > 0 and isinstance(args[0], Sphinx):
self._app = args[0]
@@ -166,14 +166,14 @@ class SphinxDummyWriter(UnfilteredWriter):
pass
-def SphinxDummySourceClass(source: Any, *args, **kwargs) -> Any:
+def SphinxDummySourceClass(source: Any, *args: Any, **kwargs: Any) -> Any:
"""Bypass source object as is to cheat Publisher."""
return source
class SphinxFileInput(FileInput):
"""A basic FileInput for Sphinx."""
- def __init__(self, *args, **kwargs) -> None:
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
kwargs['error_handler'] = 'sphinx'
super().__init__(*args, **kwargs)
diff --git a/sphinx/jinja2glue.py b/sphinx/jinja2glue.py
index 060b9f1bd..e943cfb1e 100644
--- a/sphinx/jinja2glue.py
+++ b/sphinx/jinja2glue.py
@@ -4,7 +4,7 @@
Glue code for the jinja2 templating engine.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -103,7 +103,7 @@ class idgen:
@contextfunction
-def warning(context: Dict, message: str, *args, **kwargs) -> str:
+def warning(context: Dict, message: str, *args: Any, **kwargs: Any) -> str:
if 'pagename' in context:
filename = context.get('pagename') + context.get('file_suffix', '')
message = 'in rendering %s: %s' % (filename, message)
diff --git a/sphinx/locale/__init__.py b/sphinx/locale/__init__.py
index 34427f454..82aefe91e 100644
--- a/sphinx/locale/__init__.py
+++ b/sphinx/locale/__init__.py
@@ -222,7 +222,7 @@ def get_translation(catalog, namespace='general'):
.. versionadded:: 1.8
"""
- def gettext(message: str, *args) -> str:
+ def gettext(message: str, *args: Any) -> str:
if not is_translator_registered(catalog, namespace):
# not initialized yet
return _TranslationProxy(_lazy_translate, catalog, namespace, message) # type: ignore # NOQA
diff --git a/sphinx/parsers.py b/sphinx/parsers.py
index 6c09d65b2..2a61971f3 100644
--- a/sphinx/parsers.py
+++ b/sphinx/parsers.py
@@ -4,7 +4,7 @@
A Base class for additional parsers.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/project.py b/sphinx/project.py
index 13ac6d9fd..d63af1fcb 100644
--- a/sphinx/project.py
+++ b/sphinx/project.py
@@ -4,7 +4,7 @@
Utility function and classes for Sphinx projects.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/pycode/__init__.py b/sphinx/pycode/__init__.py
index 92153d1d0..12bd8d9ef 100644
--- a/sphinx/pycode/__init__.py
+++ b/sphinx/pycode/__init__.py
@@ -4,25 +4,76 @@
Utilities parsing and analyzing Python code.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
+import tokenize
+import warnings
+from importlib import import_module
from io import StringIO
from os import path
-from typing import Any, Dict, IO, List, Tuple
+from typing import Any, Dict, IO, List, Tuple, Optional
from zipfile import ZipFile
+from sphinx.deprecation import RemovedInSphinx40Warning
from sphinx.errors import PycodeError
from sphinx.pycode.parser import Parser
-from sphinx.util import get_module_source, detect_encoding
class ModuleAnalyzer:
# cache for analyzer objects -- caches both by module and file name
cache = {} # type: Dict[Tuple[str, str], Any]
+ @staticmethod
+ def get_module_source(modname: str) -> Tuple[Optional[str], Optional[str]]:
+ """Try to find the source code for a module.
+
+ Returns ('filename', 'source'). One of it can be None if
+ no filename or source found
+ """
+ try:
+ mod = import_module(modname)
+ except Exception as err:
+ raise PycodeError('error importing %r' % modname, err)
+ loader = getattr(mod, '__loader__', None)
+ filename = getattr(mod, '__file__', None)
+ if loader and getattr(loader, 'get_source', None):
+ # prefer Native loader, as it respects #coding directive
+ try:
+ source = loader.get_source(modname)
+ if source:
+ # no exception and not None - it must be module source
+ return filename, source
+ except ImportError:
+ pass # Try other "source-mining" methods
+ if filename is None and loader and getattr(loader, 'get_filename', None):
+ # have loader, but no filename
+ try:
+ filename = loader.get_filename(modname)
+ except ImportError as err:
+ raise PycodeError('error getting filename for %r' % modname, err)
+ if filename is None:
+ # all methods for getting filename failed, so raise...
+ raise PycodeError('no source found for module %r' % modname)
+ filename = path.normpath(path.abspath(filename))
+ if filename.lower().endswith(('.pyo', '.pyc')):
+ filename = filename[:-1]
+ if not path.isfile(filename) and path.isfile(filename + 'w'):
+ filename += 'w'
+ elif not filename.lower().endswith(('.py', '.pyw')):
+ raise PycodeError('source is not a .py file: %r' % filename)
+ elif ('.egg' + path.sep) in filename:
+ pat = '(?<=\\.egg)' + re.escape(path.sep)
+ eggpath, _ = re.split(pat, filename, 1)
+ if path.isfile(eggpath):
+ return filename, None
+
+ if not path.isfile(filename):
+ raise PycodeError('source file is not present: %r' % filename)
+ return filename, None
+
@classmethod
def for_string(cls, string: str, modname: str, srcname: str = '<string>'
) -> "ModuleAnalyzer":
@@ -33,8 +84,8 @@ class ModuleAnalyzer:
if ('file', filename) in cls.cache:
return cls.cache['file', filename]
try:
- with open(filename, 'rb') as f:
- obj = cls(f, modname, filename)
+ with tokenize.open(filename) as f:
+ obj = cls(f, modname, filename, decoded=True)
cls.cache['file', filename] = obj
except Exception as err:
if '.egg' + path.sep in filename:
@@ -63,11 +114,11 @@ class ModuleAnalyzer:
return entry
try:
- type, source = get_module_source(modname)
- if type == 'string':
- obj = cls.for_string(source, modname)
- else:
- obj = cls.for_file(source, modname)
+ filename, source = cls.get_module_source(modname)
+ if source is not None:
+ obj = cls.for_string(source, modname, filename or '<string>')
+ elif filename is not None:
+ obj = cls.for_file(filename, modname)
except PycodeError as err:
cls.cache['module', modname] = err
raise
@@ -81,11 +132,13 @@ class ModuleAnalyzer:
# cache the source code as well
pos = source.tell()
if not decoded:
- self.encoding = detect_encoding(source.readline)
+ warnings.warn('decode option for ModuleAnalyzer is deprecated.',
+ RemovedInSphinx40Warning)
+ self._encoding, _ = tokenize.detect_encoding(source.readline)
source.seek(pos)
- self.code = source.read().decode(self.encoding)
+ self.code = source.read().decode(self._encoding)
else:
- self.encoding = None
+ self._encoding = None
self.code = source.read()
# will be filled by parse()
@@ -96,7 +149,7 @@ class ModuleAnalyzer:
def parse(self) -> None:
"""Parse the source code."""
try:
- parser = Parser(self.code, self.encoding)
+ parser = Parser(self.code, self._encoding)
parser.parse()
self.attr_docs = {}
@@ -124,3 +177,9 @@ class ModuleAnalyzer:
self.parse()
return self.tags
+
+ @property
+ def encoding(self) -> str:
+ warnings.warn('ModuleAnalyzer.encoding is deprecated.',
+ RemovedInSphinx40Warning)
+ return self._encoding
diff --git a/sphinx/pycode/parser.py b/sphinx/pycode/parser.py
index 690f4297e..c14d5773b 100644
--- a/sphinx/pycode/parser.py
+++ b/sphinx/pycode/parser.py
@@ -4,7 +4,7 @@
Utilities parsing and analyzing Python code.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import ast
@@ -117,7 +117,7 @@ class Token:
else:
raise ValueError('Unknown value: %r' % other)
- def match(self, *conditions) -> bool:
+ def match(self, *conditions: Any) -> bool:
return any(self == candidate for candidate in conditions)
def __repr__(self) -> str:
diff --git a/sphinx/pygments_styles.py b/sphinx/pygments_styles.py
index 8409356c0..c5b07e75f 100644
--- a/sphinx/pygments_styles.py
+++ b/sphinx/pygments_styles.py
@@ -4,7 +4,7 @@
Sphinx theme specific highlighting styles.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/registry.py b/sphinx/registry.py
index 685136470..04b62575a 100644
--- a/sphinx/registry.py
+++ b/sphinx/registry.py
@@ -257,7 +257,7 @@ class SphinxComponentRegistry:
else:
self.source_suffix[suffix] = filetype
- def add_source_parser(self, parser: "Type[Parser]", **kwargs) -> None:
+ def add_source_parser(self, parser: "Type[Parser]", **kwargs: Any) -> None:
logger.debug('[app] adding search source_parser: %r', parser)
# create a map from filetype to parser
@@ -301,7 +301,8 @@ class SphinxComponentRegistry:
raise ExtensionError(__('Translator for %r already exists') % name)
self.translators[name] = translator
- def add_translation_handlers(self, node: "Type[Element]", **kwargs) -> None:
+ def add_translation_handlers(self, node: "Type[Element]",
+ **kwargs: Tuple[Callable, Callable]) -> None:
logger.debug('[app] adding translation_handlers: %r, %r', node, kwargs)
for builder_name, handlers in kwargs.items():
translation_handlers = self.translation_handlers.setdefault(builder_name, {})
@@ -310,13 +311,13 @@ class SphinxComponentRegistry:
translation_handlers[node.__name__] = (visit, depart)
except ValueError:
raise ExtensionError(__('kwargs for add_node() must be a (visit, depart) '
- 'function tuple: %r=%r') % builder_name, handlers)
+ 'function tuple: %r=%r') % (builder_name, handlers))
def get_translator_class(self, builder: Builder) -> "Type[nodes.NodeVisitor]":
return self.translators.get(builder.name,
builder.default_translator_class)
- def create_translator(self, builder: Builder, *args) -> nodes.NodeVisitor:
+ def create_translator(self, builder: Builder, *args: Any) -> nodes.NodeVisitor:
translator_class = self.get_translator_class(builder)
assert translator_class, "translator not found for %s" % builder.name
translator = translator_class(*args)
diff --git a/sphinx/roles.py b/sphinx/roles.py
index 5757183ce..22f9e6124 100644
--- a/sphinx/roles.py
+++ b/sphinx/roles.py
@@ -4,7 +4,7 @@
Handlers for additional ReST roles.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -573,6 +573,7 @@ def index_role(typ: str, rawtext: str, text: str, lineno: int, inliner: Inliner,
class Index(ReferenceRole):
def run(self) -> Tuple[List[Node], List[system_message]]:
+ warnings.warn('Index role is deprecated.', RemovedInSphinx40Warning)
target_id = 'index-%s' % self.env.new_serialno('index')
if self.has_explicit_title:
# if an explicit target is given, process it as a full entry
@@ -607,7 +608,6 @@ specific_docroles = {
'file': EmphasizedLiteral(),
'samp': EmphasizedLiteral(),
'abbr': Abbreviation(),
- 'index': Index(),
} # type: Dict[str, RoleFunction]
diff --git a/sphinx/search/__init__.py b/sphinx/search/__init__.py
index 54a1aad92..aab4297a0 100644
--- a/sphinx/search/__init__.py
+++ b/sphinx/search/__init__.py
@@ -4,7 +4,7 @@
Create a full-text search index for offline search.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import html
diff --git a/sphinx/search/en.py b/sphinx/search/en.py
index 1fabef78d..23a6f9739 100644
--- a/sphinx/search/en.py
+++ b/sphinx/search/en.py
@@ -4,7 +4,7 @@
English search language: includes the JS porter stemmer.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/search/ja.py b/sphinx/search/ja.py
index 1b0a0e865..d1f444be1 100644
--- a/sphinx/search/ja.py
+++ b/sphinx/search/ja.py
@@ -4,7 +4,7 @@
Japanese search language: includes routine to split words.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/search/jssplitter.py b/sphinx/search/jssplitter.py
index 9bbbe459f..945579560 100644
--- a/sphinx/search/jssplitter.py
+++ b/sphinx/search/jssplitter.py
@@ -6,7 +6,7 @@
DO NOT EDIT. This is generated by utils/jssplitter_generator.py
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/search/zh.py b/sphinx/search/zh.py
index 62a6d1206..48f169aea 100644
--- a/sphinx/search/zh.py
+++ b/sphinx/search/zh.py
@@ -4,7 +4,7 @@
Chinese search language: includes routine to split words.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/setup_command.py b/sphinx/setup_command.py
index 06a7016d1..f55158575 100644
--- a/sphinx/setup_command.py
+++ b/sphinx/setup_command.py
@@ -7,7 +7,7 @@
:author: Sebastian Wiesner
:contact: basti.wiesner@gmx.net
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/templates/graphviz/graphviz.css b/sphinx/templates/graphviz/graphviz.css
index 09288cbbd..8ab69e014 100644
--- a/sphinx/templates/graphviz/graphviz.css
+++ b/sphinx/templates/graphviz/graphviz.css
@@ -4,7 +4,7 @@
*
* Sphinx stylesheet -- graphviz extension.
*
- * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
diff --git a/sphinx/testing/__init__.py b/sphinx/testing/__init__.py
index f080d8632..dd9f32462 100644
--- a/sphinx/testing/__init__.py
+++ b/sphinx/testing/__init__.py
@@ -9,6 +9,6 @@
pytest_plugins = 'sphinx.testing.fixtures'
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/testing/comparer.py b/sphinx/testing/comparer.py
index 45cae8dde..0bcd194a8 100644
--- a/sphinx/testing/comparer.py
+++ b/sphinx/testing/comparer.py
@@ -4,7 +4,7 @@
Sphinx test comparer for pytest
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import difflib
diff --git a/sphinx/testing/fixtures.py b/sphinx/testing/fixtures.py
index 443a7dd5c..c6dd7ecdf 100644
--- a/sphinx/testing/fixtures.py
+++ b/sphinx/testing/fixtures.py
@@ -4,7 +4,7 @@
Sphinx test fixtures for pytest
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/testing/path.py b/sphinx/testing/path.py
index d2fc4f31e..1c883af2f 100644
--- a/sphinx/testing/path.py
+++ b/sphinx/testing/path.py
@@ -2,7 +2,7 @@
sphinx.testing.path
~~~~~~~~~~~~~~~~~~~
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -124,17 +124,17 @@ class path(str):
def utime(self, arg: Any) -> None:
os.utime(self, arg)
- def open(self, mode: str = 'r', **kwargs) -> IO:
+ def open(self, mode: str = 'r', **kwargs: Any) -> IO:
return open(self, mode, **kwargs)
- def write_text(self, text: str, encoding: str = 'utf-8', **kwargs) -> None:
+ def write_text(self, text: str, encoding: str = 'utf-8', **kwargs: Any) -> None:
"""
Writes the given `text` to the file.
"""
with open(self, 'w', encoding=encoding, **kwargs) as f:
f.write(text)
- def text(self, encoding: str = 'utf-8', **kwargs) -> str:
+ def text(self, encoding: str = 'utf-8', **kwargs: Any) -> str:
"""
Returns the text in the file.
"""
@@ -181,7 +181,7 @@ class path(str):
"""
os.makedirs(self, mode, exist_ok=exist_ok)
- def joinpath(self, *args) -> "path":
+ def joinpath(self, *args: Any) -> "path":
"""
Joins the path with the argument given and returns the result.
"""
diff --git a/sphinx/testing/restructuredtext.py b/sphinx/testing/restructuredtext.py
index 1c3a149ad..b25d7f98a 100644
--- a/sphinx/testing/restructuredtext.py
+++ b/sphinx/testing/restructuredtext.py
@@ -2,7 +2,7 @@
sphinx.testing.restructuredtext
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/testing/util.py b/sphinx/testing/util.py
index 1ba3237c4..a031e2523 100644
--- a/sphinx/testing/util.py
+++ b/sphinx/testing/util.py
@@ -4,7 +4,7 @@
Sphinx test suite utilities
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import os
@@ -47,7 +47,7 @@ def assert_startswith(thing: str, prefix: str) -> None:
assert False, '%r does not start with %r' % (thing, prefix)
-def assert_node(node: nodes.Node, cls: Any = None, xpath: str = "", **kwargs) -> None:
+def assert_node(node: nodes.Node, cls: Any = None, xpath: str = "", **kwargs: Any) -> None:
if cls:
if isinstance(cls, list):
assert_node(node, cls[0], xpath=xpath, **kwargs)
@@ -92,7 +92,7 @@ def etree_parse(path: str) -> Any:
class Struct:
- def __init__(self, **kwds) -> None:
+ def __init__(self, **kwds: Any) -> None:
self.__dict__.update(kwds)
@@ -165,7 +165,7 @@ class SphinxTestAppWrapperForSkipBuilding:
def __getattr__(self, name: str) -> Any:
return getattr(self.app, name)
- def build(self, *args, **kw) -> None:
+ def build(self, *args: Any, **kw: Any) -> None:
if not self.app.outdir.listdir(): # type: ignore
# if listdir is empty, do build.
self.app.build(*args, **kw)
diff --git a/sphinx/themes/agogo/layout.html b/sphinx/themes/agogo/layout.html
index b46440203..cfd7ee38b 100644
--- a/sphinx/themes/agogo/layout.html
+++ b/sphinx/themes/agogo/layout.html
@@ -5,7 +5,7 @@
Sphinx layout template for the agogo theme, originally written
by Andi Albrecht.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- extends "basic/layout.html" %}
diff --git a/sphinx/themes/agogo/static/agogo.css_t b/sphinx/themes/agogo/static/agogo.css_t
index f7b257719..d74604ac1 100644
--- a/sphinx/themes/agogo/static/agogo.css_t
+++ b/sphinx/themes/agogo/static/agogo.css_t
@@ -4,7 +4,7 @@
*
* Sphinx stylesheet -- agogo theme.
*
- * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
diff --git a/sphinx/themes/basic/defindex.html b/sphinx/themes/basic/defindex.html
index 7969091ef..2f8477c31 100644
--- a/sphinx/themes/basic/defindex.html
+++ b/sphinx/themes/basic/defindex.html
@@ -4,7 +4,7 @@
Default template for the "index" page.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}{{ warn('Now base template defindex.html is deprecated.') }}
{%- extends "layout.html" %}
diff --git a/sphinx/themes/basic/domainindex.html b/sphinx/themes/basic/domainindex.html
index 3cf1bc4e8..931435f49 100644
--- a/sphinx/themes/basic/domainindex.html
+++ b/sphinx/themes/basic/domainindex.html
@@ -4,7 +4,7 @@
Template for domain indices (module index, ...).
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- extends "layout.html" %}
diff --git a/sphinx/themes/basic/genindex-single.html b/sphinx/themes/basic/genindex-single.html
index 30d709b2b..b327eb620 100644
--- a/sphinx/themes/basic/genindex-single.html
+++ b/sphinx/themes/basic/genindex-single.html
@@ -4,7 +4,7 @@
Template for a "single" page of a split index.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{% macro indexentries(firstname, links) %}
diff --git a/sphinx/themes/basic/genindex-split.html b/sphinx/themes/basic/genindex-split.html
index baa42bdcb..e9db8574d 100644
--- a/sphinx/themes/basic/genindex-split.html
+++ b/sphinx/themes/basic/genindex-split.html
@@ -4,7 +4,7 @@
Template for a "split" index overview page.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- extends "layout.html" %}
diff --git a/sphinx/themes/basic/genindex.html b/sphinx/themes/basic/genindex.html
index 3c29c10db..690823d64 100644
--- a/sphinx/themes/basic/genindex.html
+++ b/sphinx/themes/basic/genindex.html
@@ -4,7 +4,7 @@
Template for an "all-in-one" index.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{% macro indexentries(firstname, links) %}
diff --git a/sphinx/themes/basic/globaltoc.html b/sphinx/themes/basic/globaltoc.html
index 338fffa31..49c1dac08 100644
--- a/sphinx/themes/basic/globaltoc.html
+++ b/sphinx/themes/basic/globaltoc.html
@@ -4,7 +4,7 @@
Sphinx sidebar template: global table of contents.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
<h3><a href="{{ pathto(master_doc) }}">{{ _('Table of Contents') }}</a></h3>
diff --git a/sphinx/themes/basic/layout.html b/sphinx/themes/basic/layout.html
index 2c9e24930..9692ea2c4 100644
--- a/sphinx/themes/basic/layout.html
+++ b/sphinx/themes/basic/layout.html
@@ -4,7 +4,7 @@
Master layout template for Sphinx themes.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- block doctype -%}{%- if html5_doctype %}
diff --git a/sphinx/themes/basic/localtoc.html b/sphinx/themes/basic/localtoc.html
index f6d04d473..5ecacad0d 100644
--- a/sphinx/themes/basic/localtoc.html
+++ b/sphinx/themes/basic/localtoc.html
@@ -4,7 +4,7 @@
Sphinx sidebar template: local table of contents.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- if display_toc %}
diff --git a/sphinx/themes/basic/page.html b/sphinx/themes/basic/page.html
index 1f6e89429..c9c351167 100644
--- a/sphinx/themes/basic/page.html
+++ b/sphinx/themes/basic/page.html
@@ -4,7 +4,7 @@
Master template for simple pages.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- extends "layout.html" %}
diff --git a/sphinx/themes/basic/relations.html b/sphinx/themes/basic/relations.html
index 9e3f34d1a..5a2113cf0 100644
--- a/sphinx/themes/basic/relations.html
+++ b/sphinx/themes/basic/relations.html
@@ -4,7 +4,7 @@
Sphinx sidebar template: relation links.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- if prev %}
diff --git a/sphinx/themes/basic/search.html b/sphinx/themes/basic/search.html
index 3cda0feaa..2673369f2 100644
--- a/sphinx/themes/basic/search.html
+++ b/sphinx/themes/basic/search.html
@@ -4,7 +4,7 @@
Template for the search page.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- extends "layout.html" %}
diff --git a/sphinx/themes/basic/searchbox.html b/sphinx/themes/basic/searchbox.html
index 8658f9759..6ce202786 100644
--- a/sphinx/themes/basic/searchbox.html
+++ b/sphinx/themes/basic/searchbox.html
@@ -4,7 +4,7 @@
Sphinx sidebar template: quick search box.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- if pagename != "search" and builder != "singlehtml" %}
diff --git a/sphinx/themes/basic/searchresults.html b/sphinx/themes/basic/searchresults.html
index 06c2a151e..50700c158 100644
--- a/sphinx/themes/basic/searchresults.html
+++ b/sphinx/themes/basic/searchresults.html
@@ -4,7 +4,7 @@
Template for the body of the search results page.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
<h1 id="search-documentation">{{ _('Search') }}</h1>
diff --git a/sphinx/themes/basic/sourcelink.html b/sphinx/themes/basic/sourcelink.html
index 4ec8fa7c0..2ff5d1b66 100644
--- a/sphinx/themes/basic/sourcelink.html
+++ b/sphinx/themes/basic/sourcelink.html
@@ -4,7 +4,7 @@
Sphinx sidebar template: "show source" link.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- if show_source and has_source and sourcename %}
diff --git a/sphinx/themes/basic/static/basic.css_t b/sphinx/themes/basic/static/basic.css_t
index 354267567..e72db1249 100644
--- a/sphinx/themes/basic/static/basic.css_t
+++ b/sphinx/themes/basic/static/basic.css_t
@@ -4,7 +4,7 @@
*
* Sphinx stylesheet -- basic theme.
*
- * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
diff --git a/sphinx/themes/basic/static/doctools.js b/sphinx/themes/basic/static/doctools.js
index b33f87fcb..ddca10ca3 100644
--- a/sphinx/themes/basic/static/doctools.js
+++ b/sphinx/themes/basic/static/doctools.js
@@ -4,7 +4,7 @@
*
* Sphinx JavaScript utilities for all documentation.
*
- * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
diff --git a/sphinx/themes/basic/static/language_data.js_t b/sphinx/themes/basic/static/language_data.js_t
index 042a56b08..531813877 100644
--- a/sphinx/themes/basic/static/language_data.js_t
+++ b/sphinx/themes/basic/static/language_data.js_t
@@ -5,7 +5,7 @@
* This script contains the language-specific data used by searchtools.js,
* namely the list of stopwords, stemmer, scorer and splitter.
*
- * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js
index ad845872e..edef8acf5 100644
--- a/sphinx/themes/basic/static/searchtools.js
+++ b/sphinx/themes/basic/static/searchtools.js
@@ -4,7 +4,7 @@
*
* Sphinx JavaScript utilities for the full-text search.
*
- * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
diff --git a/sphinx/themes/classic/layout.html b/sphinx/themes/classic/layout.html
index 9f22787c5..c638c7f90 100644
--- a/sphinx/themes/classic/layout.html
+++ b/sphinx/themes/classic/layout.html
@@ -4,7 +4,7 @@
Sphinx layout template for the classic theme.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- extends "basic/layout.html" %}
diff --git a/sphinx/themes/classic/static/classic.css_t b/sphinx/themes/classic/static/classic.css_t
index 84a4dd0ec..bdd9db75f 100644
--- a/sphinx/themes/classic/static/classic.css_t
+++ b/sphinx/themes/classic/static/classic.css_t
@@ -4,7 +4,7 @@
*
* Sphinx stylesheet -- classic theme.
*
- * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
diff --git a/sphinx/themes/classic/static/sidebar.js_t b/sphinx/themes/classic/static/sidebar.js_t
index e118913c4..46437dae5 100644
--- a/sphinx/themes/classic/static/sidebar.js_t
+++ b/sphinx/themes/classic/static/sidebar.js_t
@@ -16,7 +16,7 @@
* Once the browser is closed the cookie is deleted and the position
* reset to the default (expanded).
*
- * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
diff --git a/sphinx/themes/epub/epub-cover.html b/sphinx/themes/epub/epub-cover.html
index 7e681147c..49a7de3a3 100644
--- a/sphinx/themes/epub/epub-cover.html
+++ b/sphinx/themes/epub/epub-cover.html
@@ -4,7 +4,7 @@
Sample template for the html cover page.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- extends "layout.html" %}
diff --git a/sphinx/themes/epub/layout.html b/sphinx/themes/epub/layout.html
index 9e0ddb628..03f03e267 100644
--- a/sphinx/themes/epub/layout.html
+++ b/sphinx/themes/epub/layout.html
@@ -4,7 +4,7 @@
Sphinx layout template for the epub theme.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- extends "basic/layout.html" %}
diff --git a/sphinx/themes/epub/static/epub.css_t b/sphinx/themes/epub/static/epub.css_t
index 052ef3371..1e81c182c 100644
--- a/sphinx/themes/epub/static/epub.css_t
+++ b/sphinx/themes/epub/static/epub.css_t
@@ -4,7 +4,7 @@
*
* Sphinx stylesheet -- epub theme.
*
- * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
diff --git a/sphinx/themes/haiku/layout.html b/sphinx/themes/haiku/layout.html
index 2f1a0b4a0..6dffe70df 100644
--- a/sphinx/themes/haiku/layout.html
+++ b/sphinx/themes/haiku/layout.html
@@ -4,7 +4,7 @@
Sphinx layout template for the haiku theme.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- extends "basic/layout.html" %}
diff --git a/sphinx/themes/haiku/static/haiku.css_t b/sphinx/themes/haiku/static/haiku.css_t
index 6b02faf89..cac283400 100644
--- a/sphinx/themes/haiku/static/haiku.css_t
+++ b/sphinx/themes/haiku/static/haiku.css_t
@@ -16,7 +16,7 @@
* Braden Ewing <brewin@gmail.com>
* Humdinger <humdingerb@gmail.com>
*
- * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
diff --git a/sphinx/themes/nature/static/nature.css_t b/sphinx/themes/nature/static/nature.css_t
index 365d68983..13c64467b 100644
--- a/sphinx/themes/nature/static/nature.css_t
+++ b/sphinx/themes/nature/static/nature.css_t
@@ -4,7 +4,7 @@
*
* Sphinx stylesheet -- nature theme.
*
- * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
diff --git a/sphinx/themes/nonav/layout.html b/sphinx/themes/nonav/layout.html
index 2f7fd0268..256b9a228 100644
--- a/sphinx/themes/nonav/layout.html
+++ b/sphinx/themes/nonav/layout.html
@@ -4,7 +4,7 @@
Sphinx layout template for the any help system theme.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- extends "basic/layout.html" %}
diff --git a/sphinx/themes/nonav/static/nonav.css b/sphinx/themes/nonav/static/nonav.css
index 4bae03214..d37c76221 100644
--- a/sphinx/themes/nonav/static/nonav.css
+++ b/sphinx/themes/nonav/static/nonav.css
@@ -4,7 +4,7 @@
*
* Sphinx stylesheet -- nonav theme.
*
- * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
diff --git a/sphinx/themes/pyramid/static/epub.css b/sphinx/themes/pyramid/static/epub.css
index b1dc4fcf1..270e9570e 100644
--- a/sphinx/themes/pyramid/static/epub.css
+++ b/sphinx/themes/pyramid/static/epub.css
@@ -4,7 +4,7 @@
*
* Sphinx stylesheet -- default theme.
*
- * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
diff --git a/sphinx/themes/pyramid/static/pyramid.css_t b/sphinx/themes/pyramid/static/pyramid.css_t
index 438a29834..48cb2ab6f 100644
--- a/sphinx/themes/pyramid/static/pyramid.css_t
+++ b/sphinx/themes/pyramid/static/pyramid.css_t
@@ -4,7 +4,7 @@
*
* Sphinx stylesheet -- pylons theme.
*
- * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
diff --git a/sphinx/themes/scrolls/layout.html b/sphinx/themes/scrolls/layout.html
index 11c571749..7474f6f31 100644
--- a/sphinx/themes/scrolls/layout.html
+++ b/sphinx/themes/scrolls/layout.html
@@ -5,7 +5,7 @@
Sphinx layout template for the scrolls theme, originally written
by Armin Ronacher.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- extends "basic/layout.html" %}
diff --git a/sphinx/themes/scrolls/static/scrolls.css_t b/sphinx/themes/scrolls/static/scrolls.css_t
index 15729e16b..b01d4ad9f 100644
--- a/sphinx/themes/scrolls/static/scrolls.css_t
+++ b/sphinx/themes/scrolls/static/scrolls.css_t
@@ -4,7 +4,7 @@
*
* Sphinx stylesheet -- scrolls theme.
*
- * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
diff --git a/sphinx/themes/sphinxdoc/layout.html b/sphinx/themes/sphinxdoc/layout.html
index f0e93daae..bdae9a441 100644
--- a/sphinx/themes/sphinxdoc/layout.html
+++ b/sphinx/themes/sphinxdoc/layout.html
@@ -4,7 +4,7 @@
Sphinx layout template for the sphinxdoc theme.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- extends "basic/layout.html" %}
diff --git a/sphinx/themes/sphinxdoc/static/sphinxdoc.css_t b/sphinx/themes/sphinxdoc/static/sphinxdoc.css_t
index 0a7d37e97..4034c617d 100644
--- a/sphinx/themes/sphinxdoc/static/sphinxdoc.css_t
+++ b/sphinx/themes/sphinxdoc/static/sphinxdoc.css_t
@@ -5,7 +5,7 @@
* Sphinx stylesheet -- sphinxdoc theme. Originally created by
* Armin Ronacher for Werkzeug.
*
- * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
diff --git a/sphinx/themes/traditional/static/traditional.css_t b/sphinx/themes/traditional/static/traditional.css_t
index 4276f7006..68719dcd1 100644
--- a/sphinx/themes/traditional/static/traditional.css_t
+++ b/sphinx/themes/traditional/static/traditional.css_t
@@ -4,7 +4,7 @@
*
* Sphinx stylesheet -- traditional docs.python.org theme.
*
- * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
diff --git a/sphinx/theming.py b/sphinx/theming.py
index bbbac5488..13a895393 100644
--- a/sphinx/theming.py
+++ b/sphinx/theming.py
@@ -4,7 +4,7 @@
Theming support for HTML builders.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/transforms/__init__.py b/sphinx/transforms/__init__.py
index df94aca49..922b22e46 100644
--- a/sphinx/transforms/__init__.py
+++ b/sphinx/transforms/__init__.py
@@ -4,7 +4,7 @@
Docutils transforms used by Sphinx when reading documents.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -104,7 +104,7 @@ class DefaultSubstitutions(SphinxTransform):
# run before the default Substitutions
default_priority = 210
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
# only handle those not otherwise defined in the document
to_handle = default_substitutions - set(self.document.substitution_defs)
for ref in self.document.traverse(nodes.substitution_reference):
@@ -127,7 +127,7 @@ class MoveModuleTargets(SphinxTransform):
"""
default_priority = 210
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
for node in self.document.traverse(nodes.target):
if not node['ids']:
continue
@@ -145,7 +145,7 @@ class HandleCodeBlocks(SphinxTransform):
"""
default_priority = 210
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
# move doctest blocks out of blockquotes
for node in self.document.traverse(nodes.block_quote):
if all(isinstance(child, nodes.doctest_block) for child
@@ -169,7 +169,7 @@ class AutoNumbering(SphinxTransform):
"""
default_priority = 210
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
domain = self.env.get_domain('std') # type: StandardDomain
for node in self.document.traverse(nodes.Element):
@@ -183,7 +183,7 @@ class SortIds(SphinxTransform):
"""
default_priority = 261
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
for node in self.document.traverse(nodes.section):
if len(node['ids']) > 1 and node['ids'][0].startswith('id'):
node['ids'] = node['ids'][1:] + [node['ids'][0]]
@@ -204,7 +204,7 @@ class ApplySourceWorkaround(SphinxTransform):
"""
default_priority = 10
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
for node in self.document.traverse(): # type: Node
if isinstance(node, (nodes.TextElement, nodes.image)):
apply_source_workaround(node)
@@ -216,7 +216,7 @@ class AutoIndexUpgrader(SphinxTransform):
"""
default_priority = 210
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
for node in self.document.traverse(addnodes.index):
if 'entries' in node and any(len(entry) == 4 for entry in node['entries']):
msg = __('4 column based index found. '
@@ -233,7 +233,7 @@ class ExtraTranslatableNodes(SphinxTransform):
"""
default_priority = 10
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
targets = self.config.gettext_additional_targets
target_nodes = [v for k, v in TRANSLATABLE_NODES.items() if k in targets]
if not target_nodes:
@@ -252,7 +252,7 @@ class UnreferencedFootnotesDetector(SphinxTransform):
"""
default_priority = 200
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
for node in self.document.footnotes:
if node['names'] == []:
# footnote having duplicated number. It is already warned at parser.
@@ -273,7 +273,7 @@ class DoctestTransform(SphinxTransform):
"""Set "doctest" style to each doctest_block node"""
default_priority = 500
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
for node in self.document.traverse(nodes.doctest_block):
node['classes'].append('doctest')
@@ -284,7 +284,7 @@ class FigureAligner(SphinxTransform):
"""
default_priority = 700
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
matcher = NodeMatcher(nodes.table, nodes.figure)
for node in self.document.traverse(matcher): # type: Element
node.setdefault('align', 'default')
@@ -294,7 +294,7 @@ class FilterSystemMessages(SphinxTransform):
"""Filter system messages from a doctree."""
default_priority = 999
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
filterlevel = 2 if self.config.keep_warnings else 5
for node in self.document.traverse(nodes.system_message):
if node['level'] < filterlevel:
@@ -321,7 +321,7 @@ class SphinxSmartQuotes(SmartQuotes, SphinxTransform):
"""
default_priority = 750
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
if not self.is_available():
return
@@ -370,7 +370,7 @@ class DoctreeReadEvent(SphinxTransform):
"""Emit :event:`doctree-read` event."""
default_priority = 880
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
self.app.emit('doctree-read', self.document)
@@ -378,7 +378,7 @@ class ManpageLink(SphinxTransform):
"""Find manpage section numbers and names"""
default_priority = 999
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
for node in self.document.traverse(addnodes.manpage):
manpage = ' '.join([str(x) for x in node.children
if isinstance(x, nodes.Text)])
diff --git a/sphinx/transforms/compact_bullet_list.py b/sphinx/transforms/compact_bullet_list.py
index 09274cd5f..1cde3b1f0 100644
--- a/sphinx/transforms/compact_bullet_list.py
+++ b/sphinx/transforms/compact_bullet_list.py
@@ -4,7 +4,7 @@
Docutils transforms used by Sphinx when reading documents.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -61,7 +61,7 @@ class RefOnlyBulletListTransform(SphinxTransform):
"""
default_priority = 100
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
if self.config.html_compact_lists:
return
diff --git a/sphinx/transforms/i18n.py b/sphinx/transforms/i18n.py
index d1c125a7e..e61905830 100644
--- a/sphinx/transforms/i18n.py
+++ b/sphinx/transforms/i18n.py
@@ -4,7 +4,7 @@
Docutils transforms used by Sphinx when reading documents.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -84,7 +84,7 @@ class PreserveTranslatableMessages(SphinxTransform):
"""
default_priority = 10 # this MUST be invoked before Locale transform
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
for node in self.document.traverse(addnodes.translatable):
node.preserve_original_messages()
@@ -95,7 +95,7 @@ class Locale(SphinxTransform):
"""
default_priority = 20
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
settings, source = self.document.settings, self.document['source']
msgstr = ''
@@ -480,7 +480,7 @@ class RemoveTranslatableInline(SphinxTransform):
"""
default_priority = 999
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
from sphinx.builders.gettext import MessageCatalogBuilder
if isinstance(self.app.builder, MessageCatalogBuilder):
return
diff --git a/sphinx/transforms/post_transforms/__init__.py b/sphinx/transforms/post_transforms/__init__.py
index 9cb7add44..a16427dad 100644
--- a/sphinx/transforms/post_transforms/__init__.py
+++ b/sphinx/transforms/post_transforms/__init__.py
@@ -4,7 +4,7 @@
Docutils transforms used by Sphinx.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -38,7 +38,7 @@ class SphinxPostTransform(SphinxTransform):
builders = () # type: Tuple[str, ...]
formats = () # type: Tuple[str, ...]
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
if self.is_supported():
self.run(**kwargs)
@@ -51,7 +51,7 @@ class SphinxPostTransform(SphinxTransform):
return True
- def run(self, **kwargs) -> None:
+ def run(self, **kwargs: Any) -> None:
"""main method of post transforms.
Subclasses should override this method instead of ``apply()``.
@@ -66,7 +66,7 @@ class ReferencesResolver(SphinxPostTransform):
default_priority = 10
- def run(self, **kwargs) -> None:
+ def run(self, **kwargs: Any) -> None:
for node in self.document.traverse(addnodes.pending_xref):
contnode = cast(nodes.TextElement, node[0].deepcopy())
newnode = None
@@ -178,7 +178,7 @@ class ReferencesResolver(SphinxPostTransform):
class OnlyNodeTransform(SphinxPostTransform):
default_priority = 50
- def run(self, **kwargs) -> None:
+ def run(self, **kwargs: Any) -> None:
# A comment on the comment() nodes being inserted: replacing by [] would
# result in a "Losing ids" exception if there is a target node before
# the only node, so we make sure docutils can transfer the id to
diff --git a/sphinx/transforms/post_transforms/code.py b/sphinx/transforms/post_transforms/code.py
index 0707b85a8..add35647b 100644
--- a/sphinx/transforms/post_transforms/code.py
+++ b/sphinx/transforms/post_transforms/code.py
@@ -4,7 +4,7 @@
transforms for code-blocks.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -36,7 +36,7 @@ class HighlightLanguageTransform(SphinxTransform):
"""
default_priority = 400
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
visitor = HighlightLanguageVisitor(self.document,
self.config.highlight_language)
self.document.walkabout(visitor)
@@ -92,7 +92,7 @@ class TrimDoctestFlagsTransform(SphinxTransform):
"""
default_priority = HighlightLanguageTransform.default_priority + 1
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
if not self.config.trim_doctest_flags:
return
diff --git a/sphinx/transforms/post_transforms/images.py b/sphinx/transforms/post_transforms/images.py
index 69a939731..6f51bc8e0 100644
--- a/sphinx/transforms/post_transforms/images.py
+++ b/sphinx/transforms/post_transforms/images.py
@@ -4,7 +4,7 @@
Docutils transforms used by Sphinx.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -183,7 +183,7 @@ class ImageConverter(BaseImageConverter):
#: ]
conversion_rules = [] # type: List[Tuple[str, str]]
- def __init__(self, *args, **kwargs) -> None:
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
self.available = None # type: bool
# the converter is available or not.
# Will be checked at first conversion
diff --git a/sphinx/transforms/references.py b/sphinx/transforms/references.py
index 79b439f4b..e74d9657d 100644
--- a/sphinx/transforms/references.py
+++ b/sphinx/transforms/references.py
@@ -4,7 +4,7 @@
Docutils transforms used by Sphinx.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -26,7 +26,7 @@ class SubstitutionDefinitionsRemover(SphinxTransform):
# should be invoked after Substitutions process
default_priority = Substitutions.default_priority + 1
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
for node in self.document.traverse(nodes.substitution_definition):
node.parent.remove(node)
@@ -34,7 +34,7 @@ class SubstitutionDefinitionsRemover(SphinxTransform):
class SphinxDanglingReferences(DanglingReferences):
"""DanglingReferences transform which does not output info messages."""
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
try:
reporter = self.document.reporter
report_level = reporter.report_level
@@ -50,7 +50,7 @@ class SphinxDomains(SphinxTransform):
"""Collect objects to Sphinx domains for cross references."""
default_priority = 850
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
for domain in self.env.domains.values():
domain.process_doc(self.env, self.env.docname, self.document)
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py
index e8fdcfe4c..954315b86 100644
--- a/sphinx/util/__init__.py
+++ b/sphinx/util/__init__.py
@@ -4,7 +4,7 @@
Utility functions for Sphinx.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -250,6 +250,8 @@ def get_module_source(modname: str) -> Tuple[str, str]:
Can return ('file', 'filename') in which case the source is in the given
file, or ('string', 'source') which which case the source is the string.
"""
+ warnings.warn('get_module_source() is deprecated.',
+ RemovedInSphinx40Warning, stacklevel=2)
try:
mod = import_module(modname)
except Exception as err:
@@ -312,6 +314,8 @@ _coding_re = re.compile(r'coding[:=]\s*([-\w.]+)')
def detect_encoding(readline: Callable[[], bytes]) -> str:
"""Like tokenize.detect_encoding() from Py3k, but a bit simplified."""
+ warnings.warn('sphinx.util.detect_encoding() is deprecated',
+ RemovedInSphinx40Warning)
def read_or_stop() -> bytes:
try:
@@ -446,7 +450,7 @@ def force_decode(string: str, encoding: str) -> str:
class attrdict(dict):
- def __init__(self, *args, **kwargs) -> None:
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
warnings.warn('The attrdict class is deprecated.',
RemovedInSphinx40Warning, stacklevel=2)
diff --git a/sphinx/util/build_phase.py b/sphinx/util/build_phase.py
index 67a76c34a..d6193b400 100644
--- a/sphinx/util/build_phase.py
+++ b/sphinx/util/build_phase.py
@@ -4,7 +4,7 @@
Build phase of Sphinx application.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/compat.py b/sphinx/util/compat.py
index 4f756b0b0..0135899eb 100644
--- a/sphinx/util/compat.py
+++ b/sphinx/util/compat.py
@@ -4,7 +4,7 @@
modules for backward compatibility
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -40,7 +40,7 @@ class IndexEntriesMigrator(SphinxTransform):
"""Migrating indexentries from old style (4columns) to new style (5columns)."""
default_priority = 700
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
for node in self.document.traverse(addnodes.index):
for i, entries in enumerate(node['entries']):
if len(entries) == 4:
diff --git a/sphinx/util/console.py b/sphinx/util/console.py
index d73d0563e..f4c80d288 100644
--- a/sphinx/util/console.py
+++ b/sphinx/util/console.py
@@ -4,7 +4,7 @@
Format colored console output.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/docfields.py b/sphinx/util/docfields.py
index dd9854ce6..699738888 100644
--- a/sphinx/util/docfields.py
+++ b/sphinx/util/docfields.py
@@ -5,7 +5,7 @@
"Doc fields" are reST field lists in object descriptions that will
be domain-specifically transformed to a more appealing presentation.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/docstrings.py b/sphinx/util/docstrings.py
index c2fe17004..8854a1f98 100644
--- a/sphinx/util/docstrings.py
+++ b/sphinx/util/docstrings.py
@@ -4,7 +4,7 @@
Utilities for docstring processing.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py
index e00e0c0b8..16b09bd7c 100644
--- a/sphinx/util/docutils.py
+++ b/sphinx/util/docutils.py
@@ -4,7 +4,7 @@
Utility functions for docutils.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -296,7 +296,7 @@ def switch_source_input(state: State, content: StringList) -> Generator[None, No
class SphinxFileOutput(FileOutput):
"""Better FileOutput class for Sphinx."""
- def __init__(self, **kwargs) -> None:
+ def __init__(self, **kwargs: Any) -> None:
self.overwrite_if_changed = kwargs.pop('overwrite_if_changed', False)
super().__init__(**kwargs)
diff --git a/sphinx/util/fileutil.py b/sphinx/util/fileutil.py
index 4a734cc21..d8e896d48 100644
--- a/sphinx/util/fileutil.py
+++ b/sphinx/util/fileutil.py
@@ -4,7 +4,7 @@
File utility functions for Sphinx.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/i18n.py b/sphinx/util/i18n.py
index 5466e5459..1cb75637c 100644
--- a/sphinx/util/i18n.py
+++ b/sphinx/util/i18n.py
@@ -4,7 +4,7 @@
Builder superclass for all builders.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import gettext
diff --git a/sphinx/util/images.py b/sphinx/util/images.py
index dfc94d4b4..b9065838b 100644
--- a/sphinx/util/images.py
+++ b/sphinx/util/images.py
@@ -4,7 +4,7 @@
Image utility functions for Sphinx.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
index e1a92ad10..1ce5bb900 100644
--- a/sphinx/util/inspect.py
+++ b/sphinx/util/inspect.py
@@ -4,7 +4,7 @@
Helpers for inspecting Python modules.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -222,7 +222,7 @@ def isproperty(obj: Any) -> bool:
return isinstance(obj, property)
-def safe_getattr(obj: Any, name: str, *defargs) -> Any:
+def safe_getattr(obj: Any, name: str, *defargs: Any) -> Any:
"""A getattr() that turns all exceptions into AttributeErrors."""
try:
return getattr(obj, name, *defargs)
diff --git a/sphinx/util/inventory.py b/sphinx/util/inventory.py
index 43a868e95..64f4ef4e3 100644
--- a/sphinx/util/inventory.py
+++ b/sphinx/util/inventory.py
@@ -4,7 +4,7 @@
Inventory utility functions for Sphinx.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import os
diff --git a/sphinx/util/jsdump.py b/sphinx/util/jsdump.py
index 2be48a34a..1f0e258cb 100644
--- a/sphinx/util/jsdump.py
+++ b/sphinx/util/jsdump.py
@@ -5,7 +5,7 @@
This module implements a simple JavaScript serializer.
Uses the basestring encode function from simplejson by Bob Ippolito.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/jsonimpl.py b/sphinx/util/jsonimpl.py
index c5336a195..52b4f2d3e 100644
--- a/sphinx/util/jsonimpl.py
+++ b/sphinx/util/jsonimpl.py
@@ -4,7 +4,7 @@
JSON serializer implementation wrapper.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -28,19 +28,19 @@ class SphinxJSONEncoder(json.JSONEncoder):
return super().default(obj)
-def dump(obj: Any, fp: IO, *args, **kwds) -> None:
+def dump(obj: Any, fp: IO, *args: Any, **kwds: Any) -> None:
kwds['cls'] = SphinxJSONEncoder
json.dump(obj, fp, *args, **kwds)
-def dumps(obj: Any, *args, **kwds) -> str:
+def dumps(obj: Any, *args: Any, **kwds: Any) -> str:
kwds['cls'] = SphinxJSONEncoder
return json.dumps(obj, *args, **kwds)
-def load(*args, **kwds) -> Any:
+def load(*args: Any, **kwds: Any) -> Any:
return json.load(*args, **kwds)
-def loads(*args, **kwds) -> Any:
+def loads(*args: Any, **kwds: Any) -> Any:
return json.loads(*args, **kwds)
diff --git a/sphinx/util/logging.py b/sphinx/util/logging.py
index 60a409093..fb2ec2900 100644
--- a/sphinx/util/logging.py
+++ b/sphinx/util/logging.py
@@ -4,7 +4,7 @@
Logging utility functions for Sphinx.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -119,14 +119,14 @@ class SphinxWarningLogRecord(SphinxLogRecord):
class SphinxLoggerAdapter(logging.LoggerAdapter):
"""LoggerAdapter allowing ``type`` and ``subtype`` keywords."""
- def log(self, level: Union[int, str], msg: str, *args, **kwargs) -> None:
+ def log(self, level: Union[int, str], msg: str, *args: Any, **kwargs: Any) -> None:
if isinstance(level, int):
super().log(level, msg, *args, **kwargs)
else:
levelno = LEVEL_NAMES[level]
super().log(levelno, msg, *args, **kwargs)
- def verbose(self, msg: str, *args, **kwargs) -> None:
+ def verbose(self, msg: str, *args: Any, **kwargs: Any) -> None:
self.log(VERBOSE, msg, *args, **kwargs)
def process(self, msg: str, kwargs: Dict) -> Tuple[str, Dict]: # type: ignore
diff --git a/sphinx/util/matching.py b/sphinx/util/matching.py
index cd8e16e20..2d37866a6 100644
--- a/sphinx/util/matching.py
+++ b/sphinx/util/matching.py
@@ -4,7 +4,7 @@
Pattern-matching utility functions for Sphinx.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/math.py b/sphinx/util/math.py
index 2af4e4db6..2a9bd66d7 100644
--- a/sphinx/util/math.py
+++ b/sphinx/util/math.py
@@ -4,7 +4,7 @@
Utility functions for math.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py
index 53b4d056e..f33a6a001 100644
--- a/sphinx/util/nodes.py
+++ b/sphinx/util/nodes.py
@@ -4,7 +4,7 @@
Docutils node-related utility functions for Sphinx.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -60,7 +60,7 @@ class NodeMatcher:
# => [<reference ...>, <reference ...>, ...]
"""
- def __init__(self, *classes: "Type[Node]", **attrs) -> None:
+ def __init__(self, *classes: "Type[Node]", **attrs: Any) -> None:
self.classes = classes
self.attrs = attrs
diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py
index 90129b1e3..e44211cf9 100644
--- a/sphinx/util/osutil.py
+++ b/sphinx/util/osutil.py
@@ -4,7 +4,7 @@
Operating system-related utility functions for Sphinx.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/parallel.py b/sphinx/util/parallel.py
index 0ff0ec116..ddcdaa316 100644
--- a/sphinx/util/parallel.py
+++ b/sphinx/util/parallel.py
@@ -4,7 +4,7 @@
Parallel building utilities.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/png.py b/sphinx/util/png.py
index 911547db6..c7f73fd50 100644
--- a/sphinx/util/png.py
+++ b/sphinx/util/png.py
@@ -4,7 +4,7 @@
PNG image manipulation helpers.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py
index 18c44ad18..ba4f83a71 100644
--- a/sphinx/util/pycompat.py
+++ b/sphinx/util/pycompat.py
@@ -4,7 +4,7 @@
Stuff for Python version compatibility.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/requests.py b/sphinx/util/requests.py
index dfadfcabe..d9d1d1b2c 100644
--- a/sphinx/util/requests.py
+++ b/sphinx/util/requests.py
@@ -4,14 +4,14 @@
Simple requests package loader
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import sys
import warnings
from contextlib import contextmanager
-from typing import Generator, Union
+from typing import Any, Generator, Union
from urllib.parse import urlsplit
import requests
@@ -54,7 +54,7 @@ def is_ssl_error(exc: Exception) -> bool:
@contextmanager
-def ignore_insecure_warning(**kwargs) -> Generator[None, None, None]:
+def ignore_insecure_warning(**kwargs: Any) -> Generator[None, None, None]:
with warnings.catch_warnings():
if not kwargs.get('verify') and InsecureRequestWarning:
# ignore InsecureRequestWarning if verify=False
@@ -95,7 +95,7 @@ def _get_user_agent(config: Config) -> str:
])
-def get(url: str, **kwargs) -> requests.Response:
+def get(url: str, **kwargs: Any) -> requests.Response:
"""Sends a GET request like requests.get().
This sets up User-Agent header and TLS verification automatically."""
@@ -111,7 +111,7 @@ def get(url: str, **kwargs) -> requests.Response:
return requests.get(url, **kwargs)
-def head(url: str, **kwargs) -> requests.Response:
+def head(url: str, **kwargs: Any) -> requests.Response:
"""Sends a HEAD request like requests.head().
This sets up User-Agent header and TLS verification automatically."""
diff --git a/sphinx/util/rst.py b/sphinx/util/rst.py
index 0824e413f..33acaa0e7 100644
--- a/sphinx/util/rst.py
+++ b/sphinx/util/rst.py
@@ -4,7 +4,7 @@
reST helper functions.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/stemmer/__init__.py b/sphinx/util/stemmer/__init__.py
index 8d8d36c68..94aaa136d 100644
--- a/sphinx/util/stemmer/__init__.py
+++ b/sphinx/util/stemmer/__init__.py
@@ -4,7 +4,7 @@
Word stemming utilities for Sphinx.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/tags.py b/sphinx/util/tags.py
index 7e7ba4661..1662a06f0 100644
--- a/sphinx/util/tags.py
+++ b/sphinx/util/tags.py
@@ -2,7 +2,7 @@
sphinx.util.tags
~~~~~~~~~~~~~~~~
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/template.py b/sphinx/util/template.py
index e6e72d079..1337f407c 100644
--- a/sphinx/util/template.py
+++ b/sphinx/util/template.py
@@ -4,7 +4,7 @@
Templates utility functions for Sphinx.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/texescape.py b/sphinx/util/texescape.py
index 734809d1f..afa1c349e 100644
--- a/sphinx/util/texescape.py
+++ b/sphinx/util/texescape.py
@@ -4,7 +4,7 @@
TeX escaping helper.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py
index 67f396e73..1b2ec3f60 100644
--- a/sphinx/util/typing.py
+++ b/sphinx/util/typing.py
@@ -4,7 +4,7 @@
The composit types for Sphinx.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/versioning.py b/sphinx/versioning.py
index 102a1205f..502bf361c 100644
--- a/sphinx/versioning.py
+++ b/sphinx/versioning.py
@@ -5,7 +5,7 @@
Implements the low-level algorithms Sphinx uses for the versioning of
doctrees.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import pickle
@@ -152,7 +152,7 @@ class UIDTransform(SphinxTransform):
"""Add UIDs to doctree for versioning."""
default_priority = 880
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
env = self.env
old_doctree = None
if not env.versioning_condition:
diff --git a/sphinx/writers/__init__.py b/sphinx/writers/__init__.py
index f2f176b83..97543df0d 100644
--- a/sphinx/writers/__init__.py
+++ b/sphinx/writers/__init__.py
@@ -4,6 +4,6 @@
Custom docutils writers.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py
index e5d00fd2c..5530dd8f5 100644
--- a/sphinx/writers/html.py
+++ b/sphinx/writers/html.py
@@ -4,7 +4,7 @@
docutils writers handling Sphinx' custom nodes.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -12,8 +12,8 @@ import copy
import os
import posixpath
import warnings
+from typing import Any, Iterable, Tuple
from typing import cast
-from typing import Iterable, Tuple
from docutils import nodes
from docutils.nodes import Element, Node, Text
@@ -72,7 +72,7 @@ class HTMLTranslator(SphinxTranslator, BaseTranslator):
builder = None # type: StandaloneHTMLBuilder
- def __init__(self, *args) -> None:
+ def __init__(self, *args: Any) -> None:
if isinstance(args[0], nodes.document) and isinstance(args[1], Builder):
document, builder = args
else:
diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py
index e6bf0c9b2..4d6089718 100644
--- a/sphinx/writers/html5.py
+++ b/sphinx/writers/html5.py
@@ -4,15 +4,15 @@
Experimental docutils writers for HTML5 handling Sphinx' custom nodes.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import os
import posixpath
import warnings
+from typing import Any, Iterable, Tuple
from typing import cast
-from typing import Iterable, Tuple
from docutils import nodes
from docutils.nodes import Element, Node, Text
@@ -44,7 +44,7 @@ class HTML5Translator(SphinxTranslator, BaseTranslator):
builder = None # type: StandaloneHTMLBuilder
- def __init__(self, *args) -> None:
+ def __init__(self, *args: Any) -> None:
if isinstance(args[0], nodes.document) and isinstance(args[1], Builder):
document, builder = args
else:
diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py
index db326406d..616d786e3 100644
--- a/sphinx/writers/latex.py
+++ b/sphinx/writers/latex.py
@@ -7,7 +7,7 @@
Much of this code is adapted from Dave Kuhlman's "docpy" writer from his
docutils sandbox.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
diff --git a/sphinx/writers/manpage.py b/sphinx/writers/manpage.py
index c9ae41609..7da2f4e8f 100644
--- a/sphinx/writers/manpage.py
+++ b/sphinx/writers/manpage.py
@@ -4,7 +4,7 @@
Manual page writer, extended for Sphinx custom nodes.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -60,7 +60,7 @@ class NestedInlineTransform:
def __init__(self, document: nodes.document) -> None:
self.document = document
- def apply(self, **kwargs) -> None:
+ def apply(self, **kwargs: Any) -> None:
matcher = NodeMatcher(nodes.literal, nodes.emphasis, nodes.strong)
for node in self.document.traverse(matcher): # type: TextElement
if any(matcher(subnode) for subnode in node):
@@ -81,7 +81,7 @@ class ManualPageTranslator(SphinxTranslator, BaseTranslator):
_docinfo = {} # type: Dict[str, Any]
- def __init__(self, *args) -> None:
+ def __init__(self, *args: Any) -> None:
if isinstance(args[0], nodes.document) and isinstance(args[1], Builder):
document, builder = args
else:
diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py
index 2a631f176..9c30244e9 100644
--- a/sphinx/writers/texinfo.py
+++ b/sphinx/writers/texinfo.py
@@ -4,7 +4,7 @@
Custom docutils writer for Texinfo.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -19,6 +19,7 @@ from docutils.nodes import Element, Node, Text
from sphinx import addnodes, __display_version__
from sphinx.domains import IndexEntry
+from sphinx.domains.index import IndexDomain
from sphinx.errors import ExtensionError
from sphinx.locale import admonitionlabels, _, __
from sphinx.util import logging
@@ -495,8 +496,9 @@ class TexinfoTranslator(SphinxTranslator):
self.indices.append((indexcls.localname,
generate(content, collapsed)))
# only add the main Index if it's not empty
+ domain = cast(IndexDomain, self.builder.env.get_domain('index'))
for docname in self.builder.docnames:
- if self.builder.env.indexentries[docname]:
+ if domain.entries[docname]:
self.indices.append((_('Index'), '\n@printindex ge\n'))
break
diff --git a/sphinx/writers/text.py b/sphinx/writers/text.py
index 3c105467e..9b9f8e62a 100644
--- a/sphinx/writers/text.py
+++ b/sphinx/writers/text.py
@@ -4,7 +4,7 @@
Custom docutils writer for plain text.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import math
@@ -12,8 +12,8 @@ import os
import re
import textwrap
from itertools import groupby, chain
+from typing import Any, Dict, List, Iterable, Optional, Set, Tuple, Union
from typing import cast
-from typing import Dict, List, Iterable, Optional, Set, Tuple, Union
from docutils import nodes, writers
from docutils.nodes import Element, Node, Text
@@ -360,7 +360,7 @@ MAXWIDTH = 70
STDINDENT = 3
-def my_wrap(text: str, width: int = MAXWIDTH, **kwargs) -> List[str]:
+def my_wrap(text: str, width: int = MAXWIDTH, **kwargs: Any) -> List[str]:
w = TextWrapper(width=width, **kwargs)
return w.wrap(text)
diff --git a/sphinx/writers/xml.py b/sphinx/writers/xml.py
index 64da854e5..d007898ba 100644
--- a/sphinx/writers/xml.py
+++ b/sphinx/writers/xml.py
@@ -4,10 +4,12 @@
Docutils-native XML and pseudo-XML writers.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
+from typing import Any
+
from docutils.writers.docutils_xml import Writer as BaseXMLWriter
from sphinx.builders import Builder
@@ -19,7 +21,7 @@ class XMLWriter(BaseXMLWriter):
self.builder = builder
self.translator_class = self.builder.get_translator_class()
- def translate(self, *args, **kwargs) -> None:
+ def translate(self, *args: Any, **kwargs: Any) -> None:
self.document.settings.newlines = \
self.document.settings.indents = \
self.builder.env.config.xml_pretty
diff --git a/tests/roots/test-ext-graphviz/index.rst b/tests/roots/test-ext-graphviz/index.rst
index e67d1d082..e6db9b220 100644
--- a/tests/roots/test-ext-graphviz/index.rst
+++ b/tests/roots/test-ext-graphviz/index.rst
@@ -14,8 +14,9 @@ Hello |graph| graphviz world
.. digraph:: foo
:graphviz_dot: neato
+ :class: neato_graph
- bar -> baz
+ baz -> qux
.. graphviz:: graph.dot
diff --git a/tests/roots/test-pycode/cp_1251_coded.py b/tests/roots/test-pycode/cp_1251_coded.py
new file mode 100644
index 000000000..43d98f354
--- /dev/null
+++ b/tests/roots/test-pycode/cp_1251_coded.py
@@ -0,0 +1,4 @@
+#!python
+# -*- coding: windows-1251 -*-
+
+X="" #:It MUST look like X="" \ No newline at end of file
diff --git a/tests/test_environment_indexentries.py b/tests/test_environment_indexentries.py
index 5c0ab7849..cf4a52c24 100644
--- a/tests/test_environment_indexentries.py
+++ b/tests/test_environment_indexentries.py
@@ -14,9 +14,8 @@ from sphinx.environment.adapters.indexentries import IndexEntries
from sphinx.testing import restructuredtext
-@pytest.mark.sphinx('dummy')
+@pytest.mark.sphinx('dummy', freshenv=True)
def test_create_single_index(app):
- app.env.indexentries.clear()
text = (".. index:: docutils\n"
".. index:: Python\n"
".. index:: pip; install\n"
@@ -42,9 +41,8 @@ def test_create_single_index(app):
assert index[5] == ('ת', [('‏תירבע‎', [[('', '#index-7')], [], None])])
-@pytest.mark.sphinx('dummy')
+@pytest.mark.sphinx('dummy', freshenv=True)
def test_create_pair_index(app):
- app.env.indexentries.clear()
text = (".. index:: pair: docutils; reStructuredText\n"
".. index:: pair: Python; interpreter\n"
".. index:: pair: Sphinx; documentation tool\n"
@@ -73,9 +71,8 @@ def test_create_pair_index(app):
('Ель', [[], [('Sphinx', [('', '#index-4')])], None])])
-@pytest.mark.sphinx('dummy')
+@pytest.mark.sphinx('dummy', freshenv=True)
def test_create_triple_index(app):
- app.env.indexentries.clear()
text = (".. index:: triple: foo; bar; baz\n"
".. index:: triple: Python; Sphinx; reST\n")
restructuredtext.parse(app, text)
@@ -89,9 +86,8 @@ def test_create_triple_index(app):
assert index[4] == ('S', [('Sphinx', [[], [('reST, Python', [('', '#index-1')])], None])])
-@pytest.mark.sphinx('dummy')
+@pytest.mark.sphinx('dummy', freshenv=True)
def test_create_see_index(app):
- app.env.indexentries.clear()
text = (".. index:: see: docutils; reStructuredText\n"
".. index:: see: Python; interpreter\n"
".. index:: see: Sphinx; documentation tool\n")
@@ -103,9 +99,8 @@ def test_create_see_index(app):
assert index[2] == ('S', [('Sphinx', [[], [('see documentation tool', [])], None])])
-@pytest.mark.sphinx('dummy')
+@pytest.mark.sphinx('dummy', freshenv=True)
def test_create_seealso_index(app):
- app.env.indexentries.clear()
text = (".. index:: seealso: docutils; reStructuredText\n"
".. index:: seealso: Python; interpreter\n"
".. index:: seealso: Sphinx; documentation tool\n")
@@ -117,9 +112,8 @@ def test_create_seealso_index(app):
assert index[2] == ('S', [('Sphinx', [[], [('see also documentation tool', [])], None])])
-@pytest.mark.sphinx('dummy')
+@pytest.mark.sphinx('dummy', freshenv=True)
def test_create_index_by_key(app):
- app.env.indexentries.clear()
# At present, only glossary directive is able to create index key
text = (".. glossary::\n"
"\n"
diff --git a/tests/test_ext_graphviz.py b/tests/test_ext_graphviz.py
index ec905aa5f..f1ae8d17e 100644
--- a/tests/test_ext_graphviz.py
+++ b/tests/test_ext_graphviz.py
@@ -29,8 +29,9 @@ def test_graphviz_png_html(app, status, warning):
html = 'Hello <div class="graphviz"><img .*?/></div>\n graphviz world'
assert re.search(html, content, re.S)
- html = '<img src=".*?" alt="digraph {\n bar -&gt; baz\n}" class="graphviz" />'
- assert re.search(html, content, re.M)
+ html = ('<img src=".*?" alt="digraph foo {\nbaz -&gt; qux\n}" '
+ 'class="graphviz neato-graph" />')
+ assert re.search(html, content, re.S)
html = (r'<div class="figure align-right" .*?>\s*'
r'<div class="graphviz"><img .*?/></div>\s*<p class="caption">'
diff --git a/tests/test_pycode.py b/tests/test_pycode.py
index 5eccad0db..458e813f6 100644
--- a/tests/test_pycode.py
+++ b/tests/test_pycode.py
@@ -10,33 +10,50 @@
import os
import sys
+import pytest
import sphinx
from sphinx.pycode import ModuleAnalyzer
+from sphinx.errors import PycodeError
SPHINX_MODULE_PATH = os.path.splitext(sphinx.__file__)[0] + '.py'
+def test_ModuleAnalyzer_get_module_source():
+ assert ModuleAnalyzer.get_module_source('sphinx') == (sphinx.__file__, sphinx.__loader__.get_source('sphinx'))
+
+ # failed to obtain source information from builtin modules
+ with pytest.raises(PycodeError):
+ ModuleAnalyzer.get_module_source('builtins')
+ with pytest.raises(PycodeError):
+ ModuleAnalyzer.get_module_source('itertools')
+
def test_ModuleAnalyzer_for_string():
analyzer = ModuleAnalyzer.for_string('print("Hello world")', 'module_name')
assert analyzer.modname == 'module_name'
assert analyzer.srcname == '<string>'
- assert analyzer.encoding is None
def test_ModuleAnalyzer_for_file():
analyzer = ModuleAnalyzer.for_string(SPHINX_MODULE_PATH, 'sphinx')
assert analyzer.modname == 'sphinx'
assert analyzer.srcname == '<string>'
- assert analyzer.encoding is None
-def test_ModuleAnalyzer_for_module():
+def test_ModuleAnalyzer_for_module(rootdir):
analyzer = ModuleAnalyzer.for_module('sphinx')
assert analyzer.modname == 'sphinx'
assert analyzer.srcname in (SPHINX_MODULE_PATH,
os.path.abspath(SPHINX_MODULE_PATH))
- assert analyzer.encoding == 'utf-8'
+
+ path = rootdir / 'test-pycode'
+ sys.path.insert(0, path)
+ try:
+ analyzer = ModuleAnalyzer.for_module('cp_1251_coded')
+ docs = analyzer.find_attr_docs()
+ assert docs == {('', 'X'): ['It MUST look like X="\u0425"', '']}
+ finally:
+ sys.path.pop(0)
def test_ModuleAnalyzer_for_file_in_egg(rootdir):