summaryrefslogtreecommitdiff
path: root/sphinx/ext/ifconfig.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/ext/ifconfig.py')
-rw-r--r--sphinx/ext/ifconfig.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/sphinx/ext/ifconfig.py b/sphinx/ext/ifconfig.py
index 50173be83..036cbdf67 100644
--- a/sphinx/ext/ifconfig.py
+++ b/sphinx/ext/ifconfig.py
@@ -21,10 +21,15 @@
"""
from docutils import nodes
+from docutils.parsers.rst import Directive
import sphinx
from sphinx.util.nodes import set_source_info
-from sphinx.util.compat import Directive
+
+if False:
+ # For type annotation
+ from typing import Any, Dict, List # NOQA
+ from sphinx.application import Sphinx # NOQA
class ifconfig(nodes.Element):
@@ -37,9 +42,10 @@ class IfConfig(Directive):
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = True
- option_spec = {}
+ option_spec = {} # type: Dict
def run(self):
+ # type: () -> List[nodes.Node]
node = ifconfig()
node.document = self.state.document
set_source_info(self, node)
@@ -50,7 +56,8 @@ class IfConfig(Directive):
def process_ifconfig_nodes(app, doctree, docname):
- ns = dict((k, app.config[k]) for k in app.config.values)
+ # type: (Sphinx, nodes.Node, unicode) -> None
+ ns = dict((confval.name, confval.value) for confval in app.config) # type: ignore
ns.update(app.config.__dict__.copy())
ns['builder'] = app.builder.name
for node in doctree.traverse(ifconfig):
@@ -59,7 +66,7 @@ def process_ifconfig_nodes(app, doctree, docname):
except Exception as err:
# handle exceptions in a clean fashion
from traceback import format_exception_only
- msg = ''.join(format_exception_only(err.__class__, err))
+ msg = ''.join(format_exception_only(err.__class__, err)) # type: ignore
newnode = doctree.reporter.error('Exception occured in '
'ifconfig expression: \n%s' %
msg, base_node=node)
@@ -72,6 +79,7 @@ def process_ifconfig_nodes(app, doctree, docname):
def setup(app):
+ # type: (Sphinx) -> Dict[unicode, Any]
app.add_node(ifconfig)
app.add_directive('ifconfig', IfConfig)
app.connect('doctree-resolved', process_ifconfig_nodes)