diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 92c6ac7fb..9896ec884 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -470,7 +470,7 @@ def signature(subject: Callable, bound_method: bool = False, follow_wrapped: boo raise try: - # Resolve forwared reference annotations using ``get_type_hints()`` and type_aliases. + # Resolve annotations using ``get_type_hints()`` and type_aliases. annotations = typing.get_type_hints(subject, None, type_aliases) for i, param in enumerate(parameters): if param.name in annotations: diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index 7b3509b62..cc4d648be 100644 --- a/sphinx/util/typing.py +++ b/sphinx/util/typing.py @@ -258,7 +258,7 @@ def stringify(annotation: Any) -> str: if isinstance(annotation, str): if annotation.startswith("'") and annotation.endswith("'"): # might be a double Forward-ref'ed type. Go unquoting. - return annotation[1:-2] + return annotation[1:-1] else: return annotation elif isinstance(annotation, TypeVar): diff --git a/tests/test_util_inspect.py b/tests/test_util_inspect.py index 8726544a6..cbca3c5f7 100644 --- a/tests/test_util_inspect.py +++ b/tests/test_util_inspect.py @@ -177,7 +177,10 @@ def test_signature_annotations(): # Instance annotations sig = inspect.signature(f11) - assert stringify_signature(sig) == '(x: CustomAnnotation, y: 123) -> None' + if sys.version_info < (3, 10): + assert stringify_signature(sig) == '(x: CustomAnnotation, y: 123) -> None' + else: + assert stringify_signature(sig) == '(x: CustomAnnotation(), y: 123) -> None' # tuple with more than two items sig = inspect.signature(f12)