diff options
| author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-07-19 15:47:42 +0900 |
|---|---|---|
| committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-07-19 15:48:07 +0900 |
| commit | b3b7cbbd3836ecbd3ff053884aa09b92f823e9d6 (patch) | |
| tree | d100e48f5dee81b7fc9f70b4ef7d5661dc5b791b /sphinx/util | |
| parent | 5850d6b8f9569171d73f8bc5abbc9d646f5d4a77 (diff) | |
| download | sphinx-git-b3b7cbbd3836ecbd3ff053884aa09b92f823e9d6.tar.gz | |
Fix #7983: autodoc: Generator type annotation is wrongly rendered in py36
This adds a special handler (if-branch) for Generator type to stringify
them correctly. So far, they have been considered as a kind of Callable.
Diffstat (limited to 'sphinx/util')
| -rw-r--r-- | sphinx/util/typing.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index 86f9c6e5c..d71ca1b2d 100644 --- a/sphinx/util/typing.py +++ b/sphinx/util/typing.py @@ -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 |
