diff options
Diffstat (limited to 'sphinx/util')
-rw-r--r-- | sphinx/util/inspect.py | 6 | ||||
-rw-r--r-- | sphinx/util/typing.py | 11 |
2 files changed, 12 insertions, 5 deletions
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 8c724395d..e3f230dc5 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -422,8 +422,8 @@ def _should_unwrap(subject: Callable) -> bool: return False -def signature(subject: Callable, bound_method: bool = False, follow_wrapped: bool = False - ) -> inspect.Signature: +def signature(subject: Callable, bound_method: bool = False, follow_wrapped: bool = False, + type_aliases: Dict = {}) -> inspect.Signature: """Return a Signature object for the given *subject*. :param bound_method: Specify *subject* is a bound method or not @@ -453,7 +453,7 @@ def signature(subject: Callable, bound_method: bool = False, follow_wrapped: boo try: # Update unresolved annotations using ``get_type_hints()``. - annotations = typing.get_type_hints(subject) + annotations = typing.get_type_hints(subject, None, type_aliases) for i, param in enumerate(parameters): if isinstance(param.annotation, str) and param.name in annotations: parameters[i] = param.replace(annotation=annotations[param.name]) diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index e91939ec2..2987f9ae3 100644 --- a/sphinx/util/typing.py +++ b/sphinx/util/typing.py @@ -63,7 +63,11 @@ def is_system_TypeVar(typ: Any) -> bool: def stringify(annotation: Any) -> str: """Stringify type annotation object.""" if isinstance(annotation, str): - return annotation + if annotation.startswith("'") and annotation.endswith("'"): + # might be a double Forward-ref'ed type. Go unquoting. + return annotation[1:-2] + else: + return annotation elif isinstance(annotation, TypeVar): # type: ignore return annotation.__name__ elif not annotation: @@ -105,7 +109,10 @@ def _stringify_py37(annotation: Any) -> str: return repr(annotation) if getattr(annotation, '__args__', None): - if qualname == 'Union': + if not isinstance(annotation.__args__, (list, tuple)): + # broken __args__ found + pass + elif qualname == 'Union': if len(annotation.__args__) > 1 and annotation.__args__[-1] is NoneType: if len(annotation.__args__) > 2: args = ', '.join(stringify(a) for a in annotation.__args__[:-1]) |