Return type inline in return #13125
Replies: 2 comments 4 replies
-
Are you using A |
Beta Was this translation helpful? Give feedback.
-
As a workaround, it can be fixed by switching the type of from sphinx.domains.python import PyObject, PyGroupedField
for i, f in enumerate(PyObject.doc_field_types):
if f.name == "returnvalue":
PyObject.doc_field_types[i] = PyGroupedField(
f.name, label=f.label, names=f.names, rolename="class", can_collapse=True
) Then this Sphinx code: .. function:: my_test_fn(param1, param2)
Example of documentation for a function.
:param param1: Description of first parameter.
:type param1: int | str
:param param2: The second parameter.
:type param2: typing.Callable[[int | str, bool], ResultCapture]
:return ResultCapture: The result of the function.
:raise TaskNotDoneException: When an error happens. gives this output: As a bonus (depending on your point of view), it will now automatically turn multiple entries into a list. For example, this input: .. function:: my_test_fn(param1, param2)
Example of documentation for a function.
:param param1: Description of first parameter.
:type param1: int | str
:param param2: The second parameter.
:type param2: ResultCapture
:return ResultCapture: The result of the function.
:return None: If nothing to return.
:raise TaskNotDoneException: When an error happens. gives this output: I originally thought of adding a totally new type of field, rather than patching the existing None of this solves the autodoc issue by itself. That would need additional changes. But this change would at least unlock a mechanism that an autodoc change could use (under a config option of course). |
Beta Was this translation helpful? Give feedback.
-
I know I'm worrying over a triviality, but I find it a bit offensive that the return type has its own line, when the type of parameters and exceptions is inline:
I'm happy to work around this by manually putting the return type in the description of
:return:
but then it looks very different to in the parameters and exceptions. (Actually even those are different from each other - bold vs italic - but this is monospace and boxed so looks even more different):I think it would be good to be able to fold return type into the return item automatically. I'd be interested in any workaround ideas too.
Beta Was this translation helpful? Give feedback.
All reactions