Skip to content

Commit

Permalink
only convert role for pydata annotations if module is typing (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
Numerlor authored Aug 8, 2022
1 parent 0f03936 commit fb7b662
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.19.2

- Fix incorrect domain used for collections.abc.Callable.

## 1.19.1

- Fix bug for recursive type alias.
Expand Down
5 changes: 4 additions & 1 deletion src/sphinx_autodoc_typehints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ def format_annotation(annotation: Any, config: Config) -> str: # noqa: C901 # t
full_name = f"{module}.{class_name}" if module != "builtins" else class_name
fully_qualified: bool = getattr(config, "typehints_fully_qualified", False)
prefix = "" if fully_qualified or full_name == class_name else "~"
role = "data" if class_name in _PYDATA_ANNOTATIONS else "class"
if module == "typing" and class_name in _PYDATA_ANNOTATIONS:
role = "data"
else:
role = "class"
args_format = "\\[{}]"
formatted_args: str | None = ""

Expand Down
2 changes: 2 additions & 0 deletions tests/test_sphinx_autodoc_typehints.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import collections.abc
import pathlib
import re
import sys
Expand Down Expand Up @@ -153,6 +154,7 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
(int, ":py:class:`int`"),
(type(None), ":py:obj:`None`"),
(type, ":py:class:`type`"),
(collections.abc.Callable, ":py:class:`~collections.abc.Callable`"),
(Type, ":py:class:`~typing.Type`"),
(Type[A], ":py:class:`~typing.Type`\\[:py:class:`~%s.A`]" % __name__),
(Any, ":py:data:`~typing.Any`"),
Expand Down

0 comments on commit fb7b662

Please sign in to comment.