From 377c29db78974a41284e312dc851be40a1316e0e Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 30 Jan 2020 23:45:22 +0900 Subject: [PATCH] typehints: Fix wrong order of info-field-list --- sphinx/ext/autodoc/typehints.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sphinx/ext/autodoc/typehints.py b/sphinx/ext/autodoc/typehints.py index 3eb845685..acdf6479c 100644 --- a/sphinx/ext/autodoc/typehints.py +++ b/sphinx/ext/autodoc/typehints.py @@ -9,6 +9,7 @@ """ import re +from collections import OrderedDict from typing import Any, Dict, Iterable from typing import cast @@ -37,13 +38,14 @@ def record_typehints(app: Sphinx, objtype: str, name: str, obj: Any, """Record type hints to env object.""" try: if callable(obj): - annotations = app.env.temp_data.setdefault('annotations', {}).setdefault(name, {}) + annotations = app.env.temp_data.setdefault('annotations', {}) + annotation = annotations.setdefault(name, OrderedDict()) sig = inspect.signature(obj) for param in sig.parameters.values(): if param.annotation is not param.empty: - annotations[param.name] = typing.stringify(param.annotation) + annotation[param.name] = typing.stringify(param.annotation) if sig.return_annotation is not sig.empty: - annotations['return'] = typing.stringify(sig.return_annotation) + annotation['return'] = typing.stringify(sig.return_annotation) except TypeError: pass