mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #8627 from tk0miya/8315_struct.Struct
Fix #8315: autodoc: Failed to resolve struct.Struct type annotation
This commit is contained in:
commit
b2c9297bd2
1
CHANGES
1
CHANGES
@ -29,6 +29,7 @@ Bugs fixed
|
||||
class
|
||||
* #8592: autodoc: ``:meta public:`` does not effect to variables
|
||||
* #8594: autodoc: empty __all__ attribute is ignored
|
||||
* #8315: autodoc: Failed to resolve struct.Struct type annotation
|
||||
* #8306: autosummary: mocked modules are documented as empty page when using
|
||||
:recursive: option
|
||||
* #8618: html: kbd role produces incorrect HTML when compound-key separators (-,
|
||||
|
@ -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)
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
import sys
|
||||
from numbers import Integral
|
||||
from struct import Struct
|
||||
from typing import (Any, Callable, Dict, Generator, List, NewType, Optional, Tuple, TypeVar,
|
||||
Union)
|
||||
|
||||
@ -43,6 +44,7 @@ def test_restify():
|
||||
assert restify(str) == ":class:`str`"
|
||||
assert restify(None) == ":obj:`None`"
|
||||
assert restify(Integral) == ":class:`numbers.Integral`"
|
||||
assert restify(Struct) == ":class:`struct.Struct`"
|
||||
assert restify(Any) == ":obj:`Any`"
|
||||
|
||||
|
||||
@ -124,6 +126,7 @@ def test_stringify():
|
||||
assert stringify(str) == "str"
|
||||
assert stringify(None) == "None"
|
||||
assert stringify(Integral) == "numbers.Integral"
|
||||
assert restify(Struct) == ":class:`struct.Struct`"
|
||||
assert stringify(Any) == "Any"
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user