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:
Takeshi KOMIYA 2020-07-20 01:00:04 +09:00 committed by GitHub
commit d4863a80c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 deletions

View File

@ -46,6 +46,7 @@ Bugs fixed
* #7901: autodoc: type annotations for overloaded functions are not resolved * #7901: autodoc: type annotations for overloaded functions are not resolved
* #904: autodoc: An instance attribute cause a crash of autofunction directive * #904: autodoc: An instance attribute cause a crash of autofunction directive
* #1362: autodoc: ``private-members`` option does not work for class attributes * #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 * #7839: autosummary: cannot handle umlauts in function names
* #7865: autosummary: Failed to extract summary line when abbreviations found * #7865: autosummary: Failed to extract summary line when abbreviations found
* #7866: autosummary: Failed to extract correct summary line when docstring * #7866: autosummary: Failed to extract correct summary line when docstring

View File

@ -10,7 +10,7 @@
import sys import sys
import typing 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 import nodes
from docutils.parsers.rst.states import Inliner from docutils.parsers.rst.states import Inliner
@ -164,6 +164,8 @@ def _stringify_py36(annotation: Any) -> str:
# for Python 3.5.2+ # for Python 3.5.2+
if annotation.__args__ is None or len(annotation.__args__) <= 2: # type: ignore # NOQA if annotation.__args__ is None or len(annotation.__args__) <= 2: # type: ignore # NOQA
params = annotation.__args__ # type: ignore params = annotation.__args__ # type: ignore
elif annotation.__origin__ == Generator: # type: ignore
params = annotation.__args__ # type: ignore
else: # typing.Callable else: # typing.Callable
args = ', '.join(stringify(arg) for arg args = ', '.join(stringify(arg) for arg
in annotation.__args__[:-1]) # type: ignore in annotation.__args__[:-1]) # type: ignore

View File

@ -10,7 +10,9 @@
import sys import sys
from numbers import Integral 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 import pytest
@ -48,6 +50,7 @@ def test_stringify_type_hints_containers():
assert stringify(Tuple[str, ...]) == "Tuple[str, ...]" assert stringify(Tuple[str, ...]) == "Tuple[str, ...]"
assert stringify(List[Dict[str, Tuple]]) == "List[Dict[str, Tuple]]" 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(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.') @pytest.mark.skipif(sys.version_info < (3, 9), reason='python 3.9+ is required.')