Skip to content

Commit f2a77f6

Browse files
authored
Fix return tuples (#50)
1 parent 7f0216e commit f2a77f6

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

scanpydoc/elegant_typehints/formatting.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ def format_annotation(annotation: Type[Any], config: Config) -> Optional[str]:
9393

9494
curframe = inspect.currentframe()
9595
calframe = inspect.getouterframes(curframe, 2)
96-
if "process_docstring" in {calframe[2].function, calframe[3].function}:
96+
if calframe[2].function == "process_docstring" or (
97+
calframe[2].function == "_inject_types_to_docstring"
98+
and calframe[3].function == "process_docstring"
99+
):
97100
return format_both(annotation, config)
98101
else: # recursive use
99102
return _format_full(annotation, config)

scanpydoc/elegant_typehints/return_tuple.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def process_docstring(
6666
# Get return section
6767
i_prefix = None
6868
l_start = None
69-
l_end = None
7069
for l, line in enumerate(lines):
7170
if i_prefix is None:
7271
m = re_ret.match(line)

tests/test_elegant_typehints.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,21 @@ class B:
305305
ids=["Last", "First"],
306306
)
307307
@pytest.mark.parametrize(
308-
"return_ann",
309-
[t.Tuple[str, int], t.Optional[t.Tuple[str, int]]],
310-
ids=["Tuple", "Optional[Tuple]"],
308+
"return_ann, foo_rendered",
309+
[
310+
(t.Tuple[str, int], ":py:class:`str`"),
311+
(t.Optional[t.Tuple[str, int]], ":py:class:`str`"),
312+
(
313+
t.Tuple[t.Mapping[str, float], int],
314+
r":annotation-terse:`:py:class:\`~typing.Mapping\``\ "
315+
r":annotation-full:`:py:class:\`~typing.Mapping\`\["
316+
r":py:class:\`str\`, :py:class:\`float\`"
317+
r"]`",
318+
),
319+
],
320+
ids=["Tuple", "Optional[Tuple]", "Complex"],
311321
)
312-
def test_return(process_doc, docstring, return_ann):
322+
def test_return(process_doc, docstring, return_ann, foo_rendered):
313323
def fn_test():
314324
pass
315325

@@ -321,7 +331,7 @@ def fn_test():
321331
if not re.match("^:(rtype|param|annotation-(full|terse)):", l)
322332
]
323333
assert lines == [
324-
r":return: foo : :py:class:`str`",
334+
rf":return: foo : {foo_rendered}",
325335
" A foo!",
326336
r" bar : :py:class:`int`",
327337
" A bar!",

0 commit comments

Comments
 (0)