From 4877a7594c22d3c8ce8992f23292cc5579b33cb2 Mon Sep 17 00:00:00 2001 From: Kjell Braden Date: Sun, 26 Apr 2020 20:09:43 +0200 Subject: [PATCH] always use separate fields for param and type in ext.autodoc.typehints this fixes issues where annotations such as `x: typing.Tuple[int, int]` will be transformed to `:field typing.Tuple[int, int] x:`, which renders as `*int] x* (**typing.Tuple[int,**) -- ` --- sphinx/ext/autodoc/typehints.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/sphinx/ext/autodoc/typehints.py b/sphinx/ext/autodoc/typehints.py index f917dbdf3..b763bdfc7 100644 --- a/sphinx/ext/autodoc/typehints.py +++ b/sphinx/ext/autodoc/typehints.py @@ -104,24 +104,16 @@ def modify_field_list(node: nodes.field_list, annotations: Dict[str, str]) -> No continue arg = arguments.get(name, {}) - field = nodes.field() - if arg.get('param') and arg.get('type'): - # both param and type are already filled manually - continue - elif arg.get('param'): - # only param: fill type field + if not arg.get('type'): + field = nodes.field() field += nodes.field_name('', 'type ' + name) field += nodes.field_body('', nodes.paragraph('', annotation)) - elif arg.get('type'): - # only type: It's odd... + node += field + if not arg.get('param'): + field = nodes.field() field += nodes.field_name('', 'param ' + name) field += nodes.field_body('', nodes.paragraph('', '')) - else: - # both param and type are not found - field += nodes.field_name('', 'param ' + annotation + ' ' + name) - field += nodes.field_body('', nodes.paragraph('', '')) - - node += field + node += field if 'return' in annotations and 'return' not in arguments: field = nodes.field()