Skip to content

Commit

Permalink
Suppress arguments if all system defined TypeVars on py39
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed May 9, 2020
1 parent 6ce265d commit 2021b43
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sphinx/util/typing.py
Expand Up @@ -39,6 +39,12 @@
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):
Expand Down Expand Up @@ -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__)
Expand Down

0 comments on commit 2021b43

Please sign in to comment.