Repository: tox-dev/sphinx-autodoc-typehints (python)

Issue:
Property :rtype: is redundant
Looking at the output, it seems that properties have redundant types. In the test suite, `a_property` is an example. Defined like:
```py
@property
def a_property(self) -> str:
    """
    Property docstring
    """
```
The test suite asserts that the type of the property is included in two places. This strikes me as redundant and slightly confusing: does a property really "return" a value? In my opinion, the abstraction makes it look like we are "accessing" the value rather than returning it. To be specific, I want the following change in the output.
```patch
     property a_property: str
  
        Property docstring
  
-       Return type:
-          "str"
- 
```
I applied the following patch to do this:
```patch
--- a/src/sphinx_autodoc_typehints/__init__.py
+++ b/src/sphinx_autodoc_typehints/__init__.py
@@ -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)

 ```
Do people prefer the current behavior? If some people want the redundant property types, could we add a config option to opt out of it?

Pull request:
Remove redundant return type for attributes
Resolves #286.

Patch:
diff --git a/src/sphinx_autodoc_typehints/__init__.py b/src/sphinx_autodoc_typehints/__init__.py
index 504782a..a4b474f 100644
--- a/src/sphinx_autodoc_typehints/__init__.py
+++ b/src/sphinx_autodoc_typehints/__init__.py
@@ -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)
diff --git a/whitelist.txt b/whitelist.txt
index 3091ceb..be15dbc 100644
--- a/whitelist.txt
+++ b/whitelist.txt
@@ -18,12 +18,14 @@ fmt
 fn
 formatter
 func
+getitem
 getmodule
 getsource
 globals
 idx
 inited
 inv
+isdatadescriptor
 isfunction
 iterdir
 kwonlyargs


Test patch:
diff --git a/tests/test_sphinx_autodoc_typehints.py b/tests/test_sphinx_autodoc_typehints.py
index 295157e..330dd06 100644
--- a/tests/test_sphinx_autodoc_typehints.py
+++ b/tests/test_sphinx_autodoc_typehints.py
@@ -118,8 +118,8 @@ else:
     # 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"
@@ -574,9 +574,6 @@ def test_sphinx_output(
 
               Property docstring
 
-              Return type:
-                 "str"
-
            static a_staticmethod(x, y, z=None)
 
               Staticmethod docstring.