diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7348464..3d10bf5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d60ae35 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "editor.formatOnSave": true, + "python.formatting.provider": "black", + "python.testing.pytestArgs": ["-v"], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} diff --git a/scanpydoc/elegant_typehints/formatting.py b/scanpydoc/elegant_typehints/formatting.py index a9c18f2..2e3f169 100644 --- a/scanpydoc/elegant_typehints/formatting.py +++ b/scanpydoc/elegant_typehints/formatting.py @@ -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. @@ -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" ): diff --git a/tests/test_elegant_typehints.py b/tests/test_elegant_typehints.py index 873e094..ae388f6 100644 --- a/tests/test_elegant_typehints.py +++ b/tests/test_elegant_typehints.py @@ -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], @@ -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}") @@ -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!", ]