Skip to content

Commit

Permalink
Remove redundant return type for attributes (#287)
Browse files Browse the repository at this point in the history
* Remove redundant return type for attributes

* Suppress flake8 possibly misspelt word lint

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix formatting

* Add comment explaining noqa

* Add getitem and isdatadescriptor to flake8 whitelist

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
hoodmane and pre-commit-ci[bot] committed Jan 15, 2023
1 parent abc497f commit a599552
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
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

0 comments on commit a599552

Please sign in to comment.