diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-01-01 07:55:12 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-01-01 07:55:12 +0300 |
commit | 1544097af546a4e5a674cce31646eb8e289dab9a (patch) | |
tree | 78e7d9a6c620ed4323c2b93bd64128c9f20392e1 /sphinx/util | |
parent | 62a0ee3fefec28259efb440778781c12db1dcbc5 (diff) | |
parent | 54ef601049f2f2a18117732e8d2b0cff551e48e6 (diff) |
Merge branch '3.x'
Diffstat (limited to 'sphinx/util')
-rw-r--r-- | sphinx/util/typing.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index 3c551a41f..90f23447b 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 @@ -91,6 +92,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'): @@ -259,6 +263,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) |