Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-12-31 08:10:55 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-12-31 08:25:05 +0300
commitf1a051fdfc72a882012f399f99b65bbe7729cb1f (patch)
tree3a120c0c7c3a873e81673d35c918b5678d2ddf3c /sphinx/util
parenta1d501d876693653fcd47e8ffd6e10ca4c48ffb6 (diff)
Fix #8315: autodoc: Failed to resolve struct.Struct type annotation
The builtin module, ``struct.Struct`` does not have correct module name since Python 3.8. This allows to refer it automatically.
Diffstat (limited to 'sphinx/util')
-rw-r--r--sphinx/util/typing.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py
index 2d4f67bba..f9807ae09 100644
--- a/sphinx/util/typing.py
+++ b/sphinx/util/typing.py
@@ -10,6 +10,7 @@
import sys
import typing
+from struct import Struct
from typing import Any, Callable, Dict, Generator, List, Optional, Tuple, TypeVar, Union
from docutils import nodes
@@ -94,6 +95,9 @@ def restify(cls: Optional["Type"]) -> str:
return ':obj:`None`'
elif cls is Ellipsis:
return '...'
+ elif cls is Struct:
+ # Before Python 3.9, struct.Struct class has incorrect __module__.
+ return ':class:`struct.Struct`'
elif inspect.isNewType(cls):
return ':class:`%s`' % cls.__name__
elif cls.__module__ in ('__builtin__', 'builtins'):
@@ -305,6 +309,9 @@ def stringify(annotation: Any) -> str:
return annotation.__qualname__
elif annotation is Ellipsis:
return '...'
+ elif annotation is Struct:
+ # Before Python 3.9, struct.Struct class has incorrect __module__.
+ return 'struct.Struct'
if sys.version_info >= (3, 7): # py37+
return _stringify_py37(annotation)