diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-05-09 18:39:59 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-09 18:39:59 +0900 |
commit | f73256176f9820351c1f529232b4c0679811e7fc (patch) | |
tree | 1a85784258e57a31167443c056bac2cf1db541f5 | |
parent | d670214403eb09372ef5b2e1dd1cf04258b84e56 (diff) | |
parent | 1fbfb7281e6298311fde3403558d6a8a3c03372f (diff) | |
download | sphinx-git-f73256176f9820351c1f529232b4c0679811e7fc.tar.gz |
Merge pull request #7640 from tk0miya/suppress_system_defined_TypeVars
Suppress system defined type vars (for 3.0.x branch)
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | sphinx/util/typing.py | 9 |
2 files changed, 9 insertions, 1 deletions
@@ -17,6 +17,7 @@ Bugs fixed ---------- * #7567: autodoc: parametrized types are shown twice for generic types +* #7637: autodoc: system defined TypeVars are shown in Python 3.9 * #7611: md5 fails when OpenSSL FIPS is enabled Testing diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index 4644b1378..08bf7203b 100644 --- a/sphinx/util/typing.py +++ b/sphinx/util/typing.py @@ -39,6 +39,12 @@ TitleGetter = Callable[[nodes.Node], str] Inventory = Dict[str, Dict[str, Tuple[str, str, str, str]]] +def is_system_TypeVar(typ: Any) -> bool: + """Check *typ* is system defined TypeVar.""" + modname = getattr(typ, '__module__', '') + return modname == 'typing' and isinstance(typ, TypeVar) # type: ignore + + def stringify(annotation: Any) -> str: """Stringify type annotation object.""" if isinstance(annotation, str): @@ -96,7 +102,8 @@ def _stringify_py37(annotation: Any) -> str: return '%s[[%s], %s]' % (qualname, args, returns) elif str(annotation).startswith('typing.Annotated'): # for py39+ return stringify(annotation.__args__[0]) - elif getattr(annotation, '_special', False): + elif all(is_system_TypeVar(a) for a in annotation.__args__): + # Suppress arguments if all system defined TypeVars (ex. Dict[KT, VT]) return qualname else: args = ', '.join(stringify(a) for a in annotation.__args__) |