diff --git a/cylc/sphinx_ext/literal_sub_include/__init__.py b/cylc/sphinx_ext/literal_sub_include/__init__.py index 459004a..4339885 100644 --- a/cylc/sphinx_ext/literal_sub_include/__init__.py +++ b/cylc/sphinx_ext/literal_sub_include/__init__.py @@ -59,8 +59,14 @@ """ +from typing import TYPE_CHECKING + from cylc.sphinx_ext.literal_sub_include.directives import LiteralSubInclude +if TYPE_CHECKING: + from sphinx.application import Sphinx + + __version__ = '1.0.0' diff --git a/cylc/sphinx_ext/literal_sub_include/directives.py b/cylc/sphinx_ext/literal_sub_include/directives.py index 7a959fa..abfc104 100644 --- a/cylc/sphinx_ext/literal_sub_include/directives.py +++ b/cylc/sphinx_ext/literal_sub_include/directives.py @@ -17,23 +17,25 @@ # ----------------------------------------------------------------------------- from functools import wraps +from typing import List from docutils.parsers.rst import directives from sphinx.directives.code import LiteralInclude, LiteralIncludeReader -def substitute(lines, items): +def substitute(lines: List[str], items: dict) -> None: """Substitute |strings| in the provided "lines" with values from "items". Example: - >>> lines = ['foo |bar| baz'] - >>> substitute(lines, {'bar': 'pub'}) + >>> lines = ['foo |bar| baz', 'foo bar |baz|'] + >>> substitute(lines, {'bar': 'pub', 'baz': 'qux'}) >>> lines - ['foo pub baz'] + ['foo pub baz', 'foo bar qux'] """ for ind, line in enumerate(lines): for key, value in items.items(): - lines[ind] = line.replace(f'|{key}|', value) + line = line.replace(f'|{key}|', value) + lines[ind] = line def substitution_decorator(fcn):