Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ repos:
hooks:
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.1.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/pycqa/isort
rev: 5.11.4
rev: 5.12.0
hooks:
- id: isort
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor.formatOnSave": true,
"python.formatting.provider": "black",
"python.testing.pytestArgs": ["-v"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
4 changes: 2 additions & 2 deletions scanpydoc/elegant_typehints/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _format_terse(annotation: Type[Any], config: Config) -> str:


def format_annotation(annotation: Type[Any], config: Config) -> Optional[str]:
r"""Generate reStructuredText containing links to the types.
"""Generate reStructuredText containing links to the types.

Unlike :func:`sphinx_autodoc_typehints.format_annotation`,
it tries to achieve a simpler style as seen in numeric packages like numpy.
Expand All @@ -93,7 +93,7 @@ def format_annotation(annotation: Type[Any], config: Config) -> Optional[str]:

curframe = inspect.currentframe()
calframe = inspect.getouterframes(curframe, 2)
if calframe[2].function == "process_docstring" or (
if calframe[2].function in {"process_docstring", "_inject_signature"} or (
calframe[2].function == "_inject_types_to_docstring"
and calframe[3].function == "process_docstring"
):
Expand Down
8 changes: 2 additions & 6 deletions tests/test_elegant_typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ def test_classes_get_added(app, parse):
# t.NoReturn,
t.Callable[[int], None],
# t.ClassVar[t.Any],
t.Optional[int],
t.Tuple[int, str],
t.Tuple[float, ...],
t.Union[int, str],
Expand All @@ -212,9 +211,6 @@ def test_typing_classes(app, annotation, formatter):
)
if formatter is _format_terse and name in {"Union", "Callable"}:
pytest.skip("Tested elsewhere")
args = get_args(annotation)
if name == "Union" and len(args) == 2 and type(None) in args:
name = "Optional"
output = formatter(annotation, app.config)
assert output is None or output.startswith(f":py:data:`typing.{name}")

Expand Down Expand Up @@ -331,9 +327,9 @@ def fn_test():
if not re.match("^:(rtype|param|annotation-(full|terse)):", l)
]
assert lines == [
rf":return: foo : {foo_rendered}",
f":return: foo : {foo_rendered}",
" A foo!",
r" bar : :py:class:`int`",
" bar : :py:class:`int`",
" A bar!",
]

Expand Down