Skip to content

Commit

Permalink
Fix typing errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Dec 25, 2021
1 parent b1a4b9e commit 9c2cdf5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/antsibull/jinja2/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
_UNESCAPE = re.compile(r"\\(.)")


def extract_plugin_data(context: Context) -> t.Tuple[str, str]:
def extract_plugin_data(context: Context) -> t.Tuple[t.Optional[str], t.Optional[str]]:
plugin_fqcn = context.get('plugin_name')
plugin_type = context.get('plugin_type')
if plugin_fqcn is None or plugin_type is None:
Expand Down
18 changes: 9 additions & 9 deletions src/antsibull/semantic_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def _remove_array_stubs(text: str) -> str:
return _ARRAY_STUB_RE.sub('', text)


def parse_option(text: str, plugin_fqcn: str, plugin_type: str, require_plugin=False
) -> t.Tuple[str, str, str, str, t.Optional[str]]:
def parse_option(text: str, plugin_fqcn: t.Optional[str], plugin_type: t.Optional[str],
require_plugin=False) -> t.Tuple[str, str, str, str, t.Optional[str]]:
"""
Given the contents of O(...) / :ansopt:`...` with potential escaping removed,
split it into plugin FQCN, plugin type, option link name, option name, and option value.
Expand All @@ -43,8 +43,8 @@ def parse_option(text: str, plugin_fqcn: str, plugin_type: str, require_plugin=F
return plugin_fqcn, plugin_type, _remove_array_stubs(text), text, value


def parse_return_value(text: str, plugin_fqcn: str, plugin_type: str, require_plugin=False
) -> t.Tuple[str, str, str, str, t.Optional[str]]:
def parse_return_value(text: str, plugin_fqcn: t.Optional[str], plugin_type: t.Optional[str],
require_plugin=False) -> t.Tuple[str, str, str, str, t.Optional[str]]:
"""
Given the contents of RV(...) / :ansretval:`...` with potential escaping removed,
split it into plugin FQCN, plugin type, option link name, option name, and option value.
Expand All @@ -68,15 +68,15 @@ def parse_return_value(text: str, plugin_fqcn: str, plugin_type: str, require_pl
return plugin_fqcn, plugin_type, _remove_array_stubs(text), text, value


def augment_plugin_name_type(text: str, plugin_fqcn: str, plugin_type: str) -> str:
def augment_plugin_name_type(text: str, plugin_fqcn: t.Optional[str], plugin_type: t.Optional[str]
) -> str:
"""
Given the text contents of O(...) or RV(...) and a plugin's FQCN and type, insert
the FQCN and type if they are not already present.
"""
value = None
if '=' in text:
text, value = text.split('=', 1)
if ':' not in text:
text = '{plugin_fqcn}#{plugin_type}:{text}'.format(
plugin_fqcn=plugin_fqcn, plugin_type=plugin_type, text=text)
return text if value is None else ('{text}={value}'.format(text=text, value=value))
if ':' not in text and plugin_fqcn and plugin_type:
text = f'{plugin_fqcn}#{plugin_type}:{text}'
return text if value is None else f'{text}={value}'
4 changes: 2 additions & 2 deletions src/sphinx_antsibull_ext/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def _create_ref_or_not(create_ref: t.Callable[[str, str, str], t.Optional[str]],
'refexplicit': True,
'refwarn': True,
}
refnode = addnodes.pending_xref(text, content, **options)
refnode['reftarget'] = ref
refnode = addnodes.pending_xref(text, content, **options) # pyre-ignore[19]
refnode['reftarget'] = ref # pyre-ignore[16]
return '', [refnode]


Expand Down
7 changes: 7 additions & 0 deletions stubs/jinja2/utils.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import typing as t

F = t.TypeVar("F", bound=t.Callable[..., t.Any])

def pass_context(f: F) -> F: ...
def pass_eval_context(f: F) -> F: ...
def pass_environment(f: F) -> F: ...
6 changes: 5 additions & 1 deletion tests/units/test_jinja2.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@

@pytest.mark.parametrize('text, expected', RST_IFY_DATA.items())
def test_rst_ify(text, expected):
assert rst_ify(text) == expected
context = {
'plugin_name': 'foo.bar.baz',
'plugin_type': 'module',
}
assert rst_ify(context, text) == expected


RST_ESCAPE_DATA = {
Expand Down

0 comments on commit 9c2cdf5

Please sign in to comment.