mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #7984 from tk0miya/7983_Generator_annotation
Fix #7983: autodoc: Generator type annotation is wrongly rendered in py36
This commit is contained in:
commit
d4863a80c0
1
CHANGES
1
CHANGES
@ -46,6 +46,7 @@ Bugs fixed
|
||||
* #7901: autodoc: type annotations for overloaded functions are not resolved
|
||||
* #904: autodoc: An instance attribute cause a crash of autofunction directive
|
||||
* #1362: autodoc: ``private-members`` option does not work for class attributes
|
||||
* #7983: autodoc: Generator type annotation is wrongly rendered in py36
|
||||
* #7839: autosummary: cannot handle umlauts in function names
|
||||
* #7865: autosummary: Failed to extract summary line when abbreviations found
|
||||
* #7866: autosummary: Failed to extract correct summary line when docstring
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
import sys
|
||||
import typing
|
||||
from typing import Any, Callable, Dict, List, Tuple, TypeVar, Union
|
||||
from typing import Any, Callable, Dict, Generator, List, Tuple, TypeVar, Union
|
||||
|
||||
from docutils import nodes
|
||||
from docutils.parsers.rst.states import Inliner
|
||||
@ -164,6 +164,8 @@ def _stringify_py36(annotation: Any) -> str:
|
||||
# for Python 3.5.2+
|
||||
if annotation.__args__ is None or len(annotation.__args__) <= 2: # type: ignore # NOQA
|
||||
params = annotation.__args__ # type: ignore
|
||||
elif annotation.__origin__ == Generator: # type: ignore
|
||||
params = annotation.__args__ # type: ignore
|
||||
else: # typing.Callable
|
||||
args = ', '.join(stringify(arg) for arg
|
||||
in annotation.__args__[:-1]) # type: ignore
|
||||
|
@ -10,7 +10,9 @@
|
||||
|
||||
import sys
|
||||
from numbers import Integral
|
||||
from typing import Any, Dict, List, TypeVar, Union, Callable, Tuple, Optional, Generic
|
||||
from typing import (
|
||||
Any, Dict, Generator, List, TypeVar, Union, Callable, Tuple, Optional, Generic
|
||||
)
|
||||
|
||||
import pytest
|
||||
|
||||
@ -48,6 +50,7 @@ def test_stringify_type_hints_containers():
|
||||
assert stringify(Tuple[str, ...]) == "Tuple[str, ...]"
|
||||
assert stringify(List[Dict[str, Tuple]]) == "List[Dict[str, Tuple]]"
|
||||
assert stringify(MyList[Tuple[int, int]]) == "test_util_typing.MyList[Tuple[int, int]]"
|
||||
assert stringify(Generator[None, None, None]) == "Generator[None, None, None]"
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info < (3, 9), reason='python 3.9+ is required.')
|
||||
|
Loading…
Reference in New Issue
Block a user