Skip to content

Commit 51ce0f4

Browse files
committed
Prevent -> None annotation from appearing on class constructors
1 parent 605a4ec commit 51ce0f4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

doc/conf.py

+8
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@
169169
"ref.python",
170170
]
171171

172+
def strip_init_return_typehint(app, what, name, obj, options, signature, return_annotation):
173+
# Prevent a the `-> None` annotation from appearing after classes.
174+
# This annotation comes from the `__init__`, but it renders on the class,
175+
# e.g. `Foo() -> None`
176+
# From the user's perspective, this is wrong: `Foo() -> Foo` not `None`
177+
if what == "class" and return_annotation is None:
178+
return (signature, None)
172179

173180
def warn_undocumented_members(_app, what, name, _obj, _options, lines):
174181
if len(lines) == 0:
@@ -255,3 +262,4 @@ def setup(app):
255262
app.connect('source-read', source_read)
256263
app.connect('build-finished', post_process)
257264
app.connect("autodoc-process-docstring", warn_undocumented_members)
265+
app.connect('autodoc-process-signature', strip_init_return_typehint, -1000)

0 commit comments

Comments
 (0)