Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant return type for attributes #287

Merged
merged 7 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sphinx_autodoc_typehints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def _inject_types_to_docstring(

lines.insert(insert_index, type_annotation)

if "return" in type_hints and not inspect.isclass(original_obj):
if "return" in type_hints and not inspect.isclass(original_obj) and not inspect.isdatadescriptor(original_obj):
if what == "method" and name.endswith(".__init__"): # avoid adding a return type for data class __init__
return
formatted_annotation = format_annotation(type_hints["return"], app.config)
Expand Down
7 changes: 2 additions & 5 deletions tests/test_sphinx_autodoc_typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def method(self: T) -> T:
# We could also set AbcCallable = typing.Callable and x fail the tests that
# use AbcCallable when in versions less than 3.9.
class MyGenericAlias(typing._VariadicGenericAlias, _root=True): # noqa: SC200
def __getitem__(self, params): # noqa: SC200
result = super().__getitem__(params) # noqa: SC200
def __getitem__(self, params):
result = super().__getitem__(params)
# Make a copy so we don't change the name of a cached annotation
result = result.copy_with(result.__args__)
result.__module__ = "collections.abc"
Expand Down Expand Up @@ -574,9 +574,6 @@ class InnerClass

Property docstring

Return type:
"str"

static a_staticmethod(x, y, z=None)

Staticmethod docstring.
Expand Down
2 changes: 2 additions & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ fmt
fn
formatter
func
getitem
getmodule
getsource
globals
idx
inited
inv
isdatadescriptor
isfunction
iterdir
kwonlyargs
Expand Down