Skip to content

Commit a599552

Browse files
Remove redundant return type for attributes (#287)
* 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>
1 parent abc497f commit a599552

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

src/sphinx_autodoc_typehints/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ def _inject_types_to_docstring(
611611

612612
lines.insert(insert_index, type_annotation)
613613

614-
if "return" in type_hints and not inspect.isclass(original_obj):
614+
if "return" in type_hints and not inspect.isclass(original_obj) and not inspect.isdatadescriptor(original_obj):
615615
if what == "method" and name.endswith(".__init__"): # avoid adding a return type for data class __init__
616616
return
617617
formatted_annotation = format_annotation(type_hints["return"], app.config)

tests/test_sphinx_autodoc_typehints.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ def method(self: T) -> T:
118118
# We could also set AbcCallable = typing.Callable and x fail the tests that
119119
# use AbcCallable when in versions less than 3.9.
120120
class MyGenericAlias(typing._VariadicGenericAlias, _root=True): # noqa: SC200
121-
def __getitem__(self, params): # noqa: SC200
122-
result = super().__getitem__(params) # noqa: SC200
121+
def __getitem__(self, params):
122+
result = super().__getitem__(params)
123123
# Make a copy so we don't change the name of a cached annotation
124124
result = result.copy_with(result.__args__)
125125
result.__module__ = "collections.abc"
@@ -574,9 +574,6 @@ class InnerClass
574574
575575
Property docstring
576576
577-
Return type:
578-
"str"
579-
580577
static a_staticmethod(x, y, z=None)
581578
582579
Staticmethod docstring.

whitelist.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ fmt
1818
fn
1919
formatter
2020
func
21+
getitem
2122
getmodule
2223
getsource
2324
globals
2425
idx
2526
inited
2627
inv
28+
isdatadescriptor
2729
isfunction
2830
iterdir
2931
kwonlyargs

0 commit comments

Comments
 (0)