Skip to content

Commit fb7b662

Browse files
authored
only convert role for pydata annotations if module is typing (#250)
1 parent 0f03936 commit fb7b662

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.19.2
4+
5+
- Fix incorrect domain used for collections.abc.Callable.
6+
37
## 1.19.1
48

59
- Fix bug for recursive type alias.

src/sphinx_autodoc_typehints/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ def format_annotation(annotation: Any, config: Config) -> str: # noqa: C901 # t
142142
full_name = f"{module}.{class_name}" if module != "builtins" else class_name
143143
fully_qualified: bool = getattr(config, "typehints_fully_qualified", False)
144144
prefix = "" if fully_qualified or full_name == class_name else "~"
145-
role = "data" if class_name in _PYDATA_ANNOTATIONS else "class"
145+
if module == "typing" and class_name in _PYDATA_ANNOTATIONS:
146+
role = "data"
147+
else:
148+
role = "class"
146149
args_format = "\\[{}]"
147150
formatted_args: str | None = ""
148151

tests/test_sphinx_autodoc_typehints.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import collections.abc
34
import pathlib
45
import re
56
import sys
@@ -153,6 +154,7 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
153154
(int, ":py:class:`int`"),
154155
(type(None), ":py:obj:`None`"),
155156
(type, ":py:class:`type`"),
157+
(collections.abc.Callable, ":py:class:`~collections.abc.Callable`"),
156158
(Type, ":py:class:`~typing.Type`"),
157159
(Type[A], ":py:class:`~typing.Type`\\[:py:class:`~%s.A`]" % __name__),
158160
(Any, ":py:data:`~typing.Any`"),

0 commit comments

Comments
 (0)