From b633ef636370974925c3a750759c93fe08ec88fa Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Feb 2023 01:10:36 +0000 Subject: [PATCH 1/3] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 22.12.0 → 23.1.0](https://github.com/psf/black/compare/22.12.0...23.1.0) - [github.com/pycqa/isort: 5.11.4 → 5.12.0](https://github.com/pycqa/isort/compare/5.11.4...5.12.0) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From bbd5ecec57ad24b81f9f9fe22f835a30b384ab62 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Tue, 7 Feb 2023 11:31:39 +0100 Subject: [PATCH 2/3] SAT 1.22 compat --- .vscode/settings.json | 7 +++++++ scanpydoc/elegant_typehints/formatting.py | 5 +++-- tests/test_elegant_typehints.py | 8 ++------ 3 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 .vscode/settings.json 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..decf44d 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,12 +93,13 @@ 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" ): return format_both(annotation, config) else: # recursive use + print(repr(calframe[2].function), repr(calframe[3].function)) return _format_full(annotation, config) 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!", ] From 0f655e30838ed2f842fe2cb27b15bc1f04fa2006 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Tue, 7 Feb 2023 11:32:55 +0100 Subject: [PATCH 3/3] remove debug print --- scanpydoc/elegant_typehints/formatting.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scanpydoc/elegant_typehints/formatting.py b/scanpydoc/elegant_typehints/formatting.py index decf44d..2e3f169 100644 --- a/scanpydoc/elegant_typehints/formatting.py +++ b/scanpydoc/elegant_typehints/formatting.py @@ -99,7 +99,6 @@ def format_annotation(annotation: Type[Any], config: Config) -> Optional[str]: ): return format_both(annotation, config) else: # recursive use - print(repr(calframe[2].function), repr(calframe[3].function)) return _format_full(annotation, config)