Skip to content

Commit 63845fb

Browse files
committed
Updated test results to match Sphinx 3.0+ output
1 parent 9a966fe commit 63845fb

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

sphinx_autodoc_typehints.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,15 @@ def process_signature(app, what: str, name: str, obj, options, signature, return
165165
for param in signature.parameters.values()
166166
]
167167

168-
if '<locals>' in obj.__qualname__:
168+
# The generated dataclass __init__() is weird and needs the second condition
169+
if '<locals>' in obj.__qualname__ and not (what == 'method' and name.endswith('.__init__')):
169170
logger.warning(
170171
'Cannot treat a function defined as a local function: "%s" (use @functools.wraps)',
171172
name)
172173
return
173174

174175
if parameters:
175-
if inspect.isclass(original_obj):
176+
if inspect.isclass(original_obj) or (what == 'method' and name.endswith('.__init__')):
176177
del parameters[0]
177178
elif what == 'method':
178179
outer = inspect.getmodule(obj)

tests/test_sphinx_autodoc_typehints.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ class InnerClass
385385
Return type:
386386
bytes
387387
388-
dummy_module.function_with_escaped_default(x='\\x08')
388+
dummy_module.function_with_escaped_default(x='\\\\x08')
389389
390390
Function docstring.
391391
@@ -466,11 +466,11 @@ class dummy_module.ClassWithTypehintsNotInline(x=None)
466466
Method docstring.
467467
468468
Parameters:
469-
**x** (*Callable**[**[**int**, **bytes**]**, **int**]*) --
469+
**x** ("Optional"["Callable"[["int", "bytes"], "int"]]) --
470470
foo
471471
472472
Return type:
473-
ClassWithTypehintsNotInline
473+
"ClassWithTypehintsNotInline"
474474
475475
dummy_module.undocumented_function(x)
476476
@@ -483,7 +483,7 @@ class dummy_module.DataClass
483483
484484
Class docstring.
485485
486-
__init__()
486+
__init__() -> None
487487
488488
{dataclass_docstring}
489489

0 commit comments

Comments
 (0)