You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. I found that when using autodoc typehints, the "Parameters" field from __init__() is duplicated in the class but without the descriptions. The return type is omitted in the class, but not in __init__(). For example,
class TestClass():
"""Class docstring"""
def __init__(self, array: list[int]) -> None:
"""Constructor docstring
:param array: Description of 'array'
"""
gives
Is this expected behavior?
I want just one set of annotations, either in the class or __init__(), depending on autoapi_python_class_content, i.e.:
"class"
"init":
"both":
I was able to achieve this by (crudely) patching _record_typehints() in _mapper.py:
def _record_typehints(self, obj):
if (
isinstance(obj, (PythonClass, PythonFunction, PythonMethod))
and not obj.overloads
) or isinstance(obj, PythonProperty):
obj_annotations = {}
+ # remove "Return type" field from __init__() doc- include_return_annotation = True+ include_return_annotation = not (isinstance(obj, PythonMethod) and obj.short_name == "__init__")
obj_data = obj.obj
if isinstance(obj, PythonClass):
constructor = obj.constructor
if constructor:
+ # remove "Parameters" field from class doc if autoapi_python_class_content=="class"+ if obj._class_content == "class":+ return
include_return_annotation = False
obj_data = constructor.obj
else:
return
for _, name, annotation, _ in obj_data["args"]:
if name and annotation:
obj_annotations[name] = annotation
return_annotation = obj_data["return_annotation"]
if include_return_annotation and return_annotation:
obj_annotations["return"] = return_annotation
self.app.env.autoapi_annotations[obj.id] = obj_annotations
Thanks.
The text was updated successfully, but these errors were encountered:
Hi. I found that when using autodoc typehints, the "Parameters" field from
__init__()
is duplicated in the class but without the descriptions. The return type is omitted in the class, but not in__init__()
. For example,gives
Is this expected behavior?
I want just one set of annotations, either in the class or
__init__()
, depending onautoapi_python_class_content
, i.e.:"class"
"init":
"both":
I was able to achieve this by (crudely) patching
_record_typehints()
in _mapper.py:Thanks.
The text was updated successfully, but these errors were encountered: